Jump to content

Msgbox and @error questions


Recommended Posts

New to Autoit, and want to know if certain functionality is available in Msgbox

Question 1:

I'm reading in input from a text file, and want the ability to skip an input if it is unacceptable. So Yes would contine the script with the text identified, No would discard the current information and the script would just select the next text input and Cancel would exit the loop. Can I do this? What would it look like?

This is what I currently have.

;MsgBox(3, "Line read:", $line)

#Region --- CodeWizard generated code Start ---

;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes, No, and Cancel, Icon=Info

Dim $iMsgBoxAnswer

$iMsgBoxAnswer = MsgBox(67,"Line read",$line)

Select

Case $iMsgBoxAnswer = 6 ;Yes

Case $iMsgBoxAnswer = 7 ;No

Case $iMsgBoxAnswer = 2 ;Cancel

ExitLoop

Question 2:

I have the following in my script:

If @error = -1 Then Exit

Why does the script contine, even when it reaches the EOF?

Thanks,

Spammeblind

Link to comment
Share on other sites

Welcome,

I'm not totally clear on what you want exactly but will assume it is some thing like this example

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
Global $found
While 1
    $line = FileReadLine($file)
    If @error Then ExitLoop
    Switch MsgBox(0x40023, 'Line read:', $line)
        Case 6 ; Yes
            $found = True
            ExitLoop
        Case 7 ; No
            ContinueLoop
        Case 2 ; Cancel
            ExitLoop
    EndSwitch
Wend

FileClose($file)

If $found Then
    MsgBox(0, 'Finished with:', $line)
EndIf

You can see that I use a variable to alert if the line was found and continue the script. No will ask again and Cancel will just exit the loop ($found will confirm that $line is no good and you can assign $line an empty string as well).

Your last question with @error should work fine if you check directly after the function call. Just use If @error Then... as I have to cover for the other error condition as well.

:)

Link to comment
Share on other sites

Sorry my request was unclear, your response is very clear. What I want to do is Case 7 ; (clear, return to While and select the next line of text). In essence skipping that record and moving to the next one. Does that make more sense?

While 1

$line = FileReadLine($file)

If @error Then ExitLoop

Switch MsgBox(0x40023, 'Line read:', $line)

Case 6 ; Yes

$found = True

ExitLoop

Case 7 ; No

(skip this one)

Case 2 ; Cancel

ExitLoop

EndSwitch

Wend

Thanks,

Spammeblind

Link to comment
Share on other sites

...What I want to do is Case 7 ; (clear, return to While...

The "ContinueLoop" that MHz used will do just that. You can add whatever code you want between the Case 7 and the ContinueLoop to "clear" stuff.

[size="1"][font="Arial"].[u].[/u][/font][/size]

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