Jump to content

Repeating the sleep function


Recommended Posts

I would start with something like this:

$WaitTime = 60000
$StringToFind = "test"
$LogFileFullPath = "C:Templogfile.txt"

While 1
If _FindInFile($StringToFind, $LogFileFullPath) Then ExitLoop
Sleep($WaitTime)
WEnd

(Note that this only checks once every time, not three times.)

For the _FindInFile function, maybe take a look at an example script by guinness:

Link to comment
Share on other sites

here is an example which reads the file in question until the string your looking for is found. it is only meant as a demonstration to learn from so don't just add it to your script and expect it to work. the way i tested it was using another script i made which changed the value in a script faster than the script checking the value.

here is my example:

$j = 0
While 1
    $bleh = bleh()                          ;call the function to check if the value is in the string
    ConsoleWrite($bleh & @CRLF)
    If $bleh == True Then                    ;if the file is in the string add 1 to the variable $j
        $j += 1
    Else
        $j = 0                              ;otherwise set it back to 0
    EndIf
    If $j >=3 Then Exit                    ;once the string has been found 3 times exit the script
    Sleep(300)
WEnd

Exit;just in case exit is never a bad thing to have

Func bleh()
    $var = FileRead(@ScriptDir & 'file1.txt');read the file
    If StringInStr($var, '1') Then;check if the file contains your string
        Return True;if yes, return true
    Else
        Return False;if no, return false
    EndIf
EndFunc

here is the other script to change the value in the file:

HotKeySet("{esc}", "_exit");so all you have to do is press escape when you want it to stop
While(1)
    Sleep(100)
    FileDelete(@ScriptDir & 'file1.txt')
    FileWrite(@ScriptDir & 'file1.txt', Random(0,1,1))
WEnd
Func _exit()
    Exit
EndFunc

to test like i did put the 2 scripts in a empty folder and run the script changing the value and then run the other one through scite.

Edited by pieeater

[spoiler]My UDFs: Login UDF[/spoiler]

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...