Mintz Posted May 25, 2007 Posted May 25, 2007 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)
PsaltyDS Posted May 25, 2007 Posted May 25, 2007 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
Mintz Posted May 25, 2007 Author Posted May 25, 2007 hey thanx a bundle. i know i'm asking on something very easy but i'm new. i'll learn
herewasplato Posted May 25, 2007 Posted May 25, 2007 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]
PsaltyDS Posted May 25, 2007 Posted May 25, 2007 I beat herewasplato's answer-bot! WooHoo! I rock! 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
herewasplato Posted May 25, 2007 Posted May 25, 2007 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]
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now