Jump to content

Really Simple 'msgbox' Question


Recommended Posts

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

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

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

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

Link to comment
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

Link to comment
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.

Link to comment
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.

Link to comment
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

Link to comment
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]

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