Jump to content

Need Assistance with a Constant Loop.


Go to solution Solved by Malkey,

Recommended Posts

Hey Guys,

I assure you I am trying on this script but was unable to get the FileWritetoLine to work correctly so I was hoping you can give me some insight. So what I am trying to do is run a constant loop which keeps writing the browser's title over and over to Line1 of a .txt file. I am able to get the title to write consistently but I was trying to have line one be overwritten each time it hits the loop.

I did not include FileWritetoLine because I was unable to get it working properlly so I only used File Write in the example below. If you can help this noob I would greatly appreciate it!

;;aol.com is the site im using for this demonstaration
#include <IE.au3>
#include <File.au3>

While 1
$oIEb = _IEAttach("Aol")
$title = (_IEPropertyGet($oIEb, "title"))
$LOG = FileWrite(@ScriptDir & "\browser.txt",$title)
Wend
Link to comment
Share on other sites

  • Solution

For FileWritetoLine() to work, the file must exist and the line number being written to must exist in the file.
 
In this example,  press Esc key to stop script and display contents of text file.

;;aol.com is the site im using for this demonstaration
#include <IE.au3>
#include <File.au3>
#include <FileConstants.au3>

HotKeySet("{ESC}", "Terminate") ; Press Esc key to stop script and display contents of text file.

Global $sFileName = @ScriptDir & "\browser.txt"
If FileExists($sFileName) Then FileDelete($sFileName)

Local $hFileOpen = FileOpen($sFileName, $FO_OVERWRITE + $FO_CREATEPATH) ; Create file
If $hFileOpen = -1 Then
    MsgBox(0, "", "An error occurred with the FileOpen().")
    Exit
EndIf
FileWrite($hFileOpen, "Title") ; Create line 1 in the file
FileClose($hFileOpen)

While 1
    Sleep(250)
    $oIEb = _IEAttach("Aol")
    $title = _IEPropertyGet($oIEb, "title")
    _FileWriteToLine($sFileName, 1, $title, 1)
WEnd

Func Terminate()
    ShellExecute($sFileName)
    Exit
EndFunc   ;==>Terminate

Edit: Added $title = _IEPropertyGet($oIEb, "title")

Edited by Malkey
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...