pshankland Posted October 16, 2006 Share Posted October 16, 2006 Have got the following small bit of code: If FileExists("C:\\Temp\\pattern.txt") = 1 Then $MyFile = FileOpen("C:\\Temp\\pattern.txt", 0) While 1 $strSoftwareVers = FileReadLine($MyFile, 1) $strSDSize = FileReadLine($MyFile, 2) If @error = -1 Then ExitLoop MsgBox(0, "Pattern Info", "Software Version: " & $strSoftwareVers & @CRLF & "SD Size: " & $strSDSize & "Mb") WEnd FileClose($MyFile) Else MsgBox(1, "File Does Not Exist", "The file does not exist") EndIf The problem is that when I press OK the msgbox dosn't terminate. I know I should be quiting when return = 1 (OK) but I am not sure how to include this within the code. Thanks. Link to comment Share on other sites More sharing options...
Xenobiologist Posted October 16, 2006 Share Posted October 16, 2006 Hi, have a look at Exit and / or ExitLoop. Do not know whether you need a loop there. So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
pshankland Posted October 16, 2006 Author Share Posted October 16, 2006 Exit worked - thanks! Next question: If I wanted to say, if the file does not exist sleep(5000) and then re-do the check? Within a batch file I would use goto but can't seem to work out how to do this in AutoIT. Thanks. Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted October 16, 2006 Share Posted October 16, 2006 (edited) Fileexists does that and u got a while 1 and wend loop to redo, or a do until, are your choices which would be best like why do you need a batch file to do this Edited October 16, 2006 by thatsgreat2345 Link to comment Share on other sites More sharing options...
pshankland Posted October 16, 2006 Author Share Posted October 16, 2006 Fileexists does that and u got a while 1 and wend loop to redo, or a do until, are your choices which would be best like why do you need a batch file to do this I don't want to use a batch file, I was just saying that within a batch file I can use the goto command to go to a certain area of the script, which I can't seem to do with AutoIT. Could you explain how I should use the loop to get this to work as in its current state if pattern.txt exists then the msgbox gets displayed, but if it dosn't then it exits the loop. I need to say wait for 5 seconds and retry the loop again. If FileExists("C:\\Temp\\pattern.txt") = 1 Then $MyFile = FileOpen("C:\\Temp\\pattern.txt", 0) While 1 $strSoftwareVers = FileReadLine($MyFile, 1) $strSDSize = FileReadLine($MyFile, 2) If @error = -1 Then ExitLoop MsgBox(0, "Pattern Info", "Software Version: " & $strSoftwareVers & @CRLF & "SD Size: " & $strSDSize & "Mb") Exit WEnd FileClose($MyFile) Else MsgBox(0, "File Does Not Exist", "The file does not exist") Exit EndIf Thanks. Pete. Link to comment Share on other sites More sharing options...
Valik Posted October 16, 2006 Share Posted October 16, 2006 You do not need to escape your forward slashes in AutoIt. The string(s) should be "C:\Temp\pattern.txt". Link to comment Share on other sites More sharing options...
pshankland Posted October 16, 2006 Author Share Posted October 16, 2006 You do not need to escape your forward slashes in AutoIt. The string(s) should be "C:\Temp\pattern.txt".Thanks for that Any suggestions with how I can sleep for 5 seconds if the file does not exist, loop this and when the file does exists go and do the ReadLine bit? Link to comment Share on other sites More sharing options...
Valuater Posted October 16, 2006 Share Posted October 16, 2006 maybe... If FileExists("C:\\Temp\\pattern.txt")Then Local $Tries = 0, $max_tries = 10 $MyFile = FileOpen("C:\\Temp\\pattern.txt", 0) While 1 $strSoftwareVers = FileReadLine($MyFile, 1) $strSDSize = FileReadLine($MyFile, 2) If @error = -1 Then ExitLoop $Tries = $Tries + 1 If $Tries >= $max_tries Then MsgBox(0, "Pattern Info", "Software Version: " & $strSoftwareVers & @CRLF & "SD Size: " & $strSDSize & "Mb") FileClose($MyFile) Exit EndIf Sleep(5000) WEnd FileClose($MyFile) Else MsgBox(0, "File Does Not Exist", "The file does not exist") Exit EndIf ********** not tested 8) Link to comment Share on other sites More sharing options...
pshankland Posted October 16, 2006 Author Share Posted October 16, 2006 Local $Tries = 0, $max_tries = 10 Can't really use this as need to loop to keep running basically until the program is closed (will look at this bit later). To explain the use of this code a bit better... A server will send out a *.txt file everytime a barcode is scanned by an operator. This *.txt file includes 2 lines both of which I need to read. The reason I need to keep looping is because you never know when the operater will scan the barcode and therefore when the server will create the *.txt. Hope this makes a bit of sense. Pete. Link to comment Share on other sites More sharing options...
Valuater Posted October 16, 2006 Share Posted October 16, 2006 maybe $max_tries = 100000000 lol 8) Link to comment Share on other sites More sharing options...
pshankland Posted October 16, 2006 Author Share Posted October 16, 2006 maybe$max_tries = 100000000 Not quite what I was after Link to comment Share on other sites More sharing options...
pshankland Posted October 16, 2006 Author Share Posted October 16, 2006 It is something like this I am after: If FileExists("C:\Temp\pattern.txt") = 1 Then $MyFile = FileOpen("C:\Temp\pattern.txt", 0) $strSoftwareVers = FileReadLine($MyFile, 1) $strSDSize = FileReadLine($MyFile, 2) MsgBox(0, "Pattern Info", "Software Version: " & $strSoftwareVers & @CRLF & "SD Size: " & $strSDSize & "Mb") Exit FileClose($MyFile) Else ; Sleep (5000) ; Goto to the start of this code and retry the fileexists EndIf As you can see it is at the 'Else' where I get stuck. Pete. Link to comment Share on other sites More sharing options...
Valuater Posted October 16, 2006 Share Posted October 16, 2006 While 1 If FileExists("C:\Temp\pattern.txt") = 1 Then $MyFile = FileOpen("C:\Temp\pattern.txt", 0) $strSoftwareVers = FileReadLine($MyFile, 1) $strSDSize = FileReadLine($MyFile, 2) MsgBox(0, "Pattern Info", "Software Version: " & $strSoftwareVers & @CRLF & "SD Size: " & $strSDSize & "Mb") FileClose($MyFile) Exit Else Sleep(5000) ; Goto to the start of this code and retry the fileexists EndIf WEnd 8) Link to comment Share on other sites More sharing options...
pshankland Posted October 16, 2006 Author Share Posted October 16, 2006 That works like a charm, but I don't understand how!!! To be honest I am a bit confused with the whole 'While 1..... Wend' Thanks. Link to comment Share on other sites More sharing options...
Valuater Posted October 16, 2006 Share Posted October 16, 2006 Welcome 8) Link to comment Share on other sites More sharing options...
dandymcgee Posted October 16, 2006 Share Posted October 16, 2006 The While - WEnd loop does whatever is in it "while" the expression is true. You simple use While 1 to do it forever (or until you tell it to ExitLoop after something has happened). This just makes it continue looping until the Ok button is pressed (at which point the Exit function occurs and causes the script to terminate). Hope I didn't confuse you too much as I'm not always the greatest teacher . - Dan [Website] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now