Sign in to follow this  
Followers 0
Mintz

While wend

6 posts in this topic

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)

Share this post


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

Share this post


Link to post
Share on other sites

hey thanx a bundle. i know i'm asking on something very easy but i'm new. i'll learn :)

Share this post


Link to post
Share on other sites

too late

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


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

Share this post


Link to post
Share on other sites

I beat herewasplato's answer-bot! WooHoo! I rock!

:):)

Typing class!?!

I'll never need to know how to type!

...if I had only known...

:-)

P.S. and your code was better too!


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

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