Sign in to follow this  
Followers 0
pshankland

Really Simple 'msgbox' Question

16 posts in this topic

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.

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by thatsgreat2345

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

You do not need to escape your forward slashes in AutoIt. The string(s) should be "C:\Temp\pattern.txt".

Share this post


Link to post
Share on other sites

You do not need to escape your forward slashes in AutoIt. The string(s) should be "C:\Temp\pattern.txt".

Thanks for that :lmao:

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?

post-16707-1161023511_thumb.jpg

Share this post


Link to post
Share on other sites

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)


NEWHeader1.png

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

maybe

$max_tries = 100000000

lol

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

maybe

$max_tries = 100000000

:lmao: Not quite what I was after :ph34r:

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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)


NEWHeader1.png

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Welcome

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

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


- Dan [Website]

Share this post


Link to post
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
Sign in to follow this  
Followers 0