Jump to content

While wend


Recommended Posts

This problem has popped up all over the place. what i am trying to get it to do, is so that if the user presses Cancel, the script exits, while if he presses OK without entering anything, it asks for a name. The problem is, the script does not exit when cancel is pressed. But it does loop fine, and it does continue past the loop if text is entered.

SetError(1)
$name = InputBox("Welcome!",  Please enter your name")
If $name = @error Then
    Exit
EndIf
While $name = "" 
    MsgBox(0, "enter a name", "enter a name")
    $name = InputBox("Welcome!", "Please enter your name")
wend
msgbox(0, "Hi", "Hi" & $name)
Link to comment
Share on other sites

I think maybe "returns @error" may not mean what you think it means. The macro @error is separate from the returned string in $name. this may do what you want:

While 1
$name = InputBox("Welcome!", "Please enter your name")
    If @error Then 
        Exit
    ElseIf $name = "" Then
        MsgBox(0, "enter a name", "enter a name")
    Else
        ExitLoop
    EndIf
WEnd
MsgBox(0, "Hi", "Hi, " & $name & ".")

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...