crz Posted June 30, 2006 Share Posted June 30, 2006 (edited) Hello AutoIt scripters. I am totaly new to AutoIt, and having a tiny problem, I guess all of you knows how to solve. - It's making the MsgBox buttons respond to the users actions. Example.. I've made a simple GUI and; If GUIGetMsg() = $GUI_EVENT_CLOSE Then MsgBox(4, "GUI", "Are you sure you want to exit?") You can probably figure out my question now; - When the user clicks "No", the script continues and when the user clicks "Yes", the script closes. Could someone please give me a short and simpel exampel of this? -I appreciate it. crz Edited June 30, 2006 by crz Steffen "crz" Jorgensenwww.crz.dkcrz@crz.dk Link to comment Share on other sites More sharing options...
McDope Posted June 30, 2006 Share Posted June 30, 2006 (edited) If GUIGetMsg() = $GUI_EVENT_CLOSE Then $myreturn = MsgBox(4, "GUI", "Are you sure you want to exit?") if $myreturn = 6 Then;-> user clicked yes Exit 0 endif if $myreturn = 7 Then;-> user clicked no DoSomethingOther() endif endif See Help File under MsgBox for other return values Edited June 30, 2006 by McDope Link to comment Share on other sites More sharing options...
taurus905 Posted June 30, 2006 Share Posted June 30, 2006 crz,Welcome to the AutoIt forum. There are lots of great places to learn here.Please try Welcome to AutoIt 1-2-3, Class... is now in SessionIn the mean time, here is one way of doing what you asked.taurus905; Exit with Question Example.au3 #include <GUIConstants.au3> GUICreate("Close this window.", 400, 200, -1, -1) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE $Answer = MsgBox(3, "Exit this program.", "Are you sure you want to quit?") Select Case $Answer = 6; Yes MsgBox(0, "Your Answer:", "You selected Yes, so this program will end") Exit Case $Answer = 7; No MsgBox(0, "Your Answer:", "You selected No, so lets continue.") Case $Answer = 2; Cancel MsgBox(0, "Your Answer:", "Your selected Cancel, so lets continue.") EndSelect EndSelect WEnd Exit "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs Link to comment Share on other sites More sharing options...
crz Posted June 30, 2006 Author Share Posted June 30, 2006 Awesome, just what I needed. Thanks. Steffen "crz" Jorgensenwww.crz.dkcrz@crz.dk Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 30, 2006 Share Posted June 30, 2006 (edited) crz, Welcome to the AutoIt forum. There are lots of great places to learn here. Please try Welcome to AutoIt 1-2-3, Class... is now in Session In the mean time, here is one way of doing what you asked. taurus905 ; Exit with Question Example.au3 #include <GUIConstants.au3> GUICreate("Close this window.", 400, 200, -1, -1) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE $Answer = MsgBox(3, "Exit this program.", "Are you sure you want to quit?") Select Case $Answer = 6; Yes MsgBox(0, "Your Answer:", "You selected Yes, so this program will end") Exit Case $Answer = 7; No MsgBox(0, "Your Answer:", "You selected No, so lets continue.") Case $Answer = 2; Cancel MsgBox(0, "Your Answer:", "Your selected Cancel, so lets continue.") EndSelect EndSelect WEnd Exit Also, if you're only interested in one of the possible answers, you can get it in a single line with the MsgBox() statement: While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then If MsgBox(4+256, "Exit this program?", "Are you sure you want to quit?") = 6 Then Exit EndIf WEndoÝ÷ Øýz-¢vwhÂÆèƸ ÙèÂÊßÙe«Þ¶kÊ+ej׫nëb¶;¬¶º·¶¶Ù¢^½é𢹱«¢+Ù]¡¥±Ä($ÀÌØíµÍôU%Ñ5Í ¤(%%ÀÌØíµÍôÀÌØíU%}Y9Q} 1=MQ¡¸%5Í ½à ЬÈÔØ°ÅÕ½Ðíá¥ÐÑ¡¥ÌÁɽɴüÅÕ½Ðì°ÅÕ½ÐíÉå½ÔÍÕÉå½ÔݹÐѼÅÕ¥ÐüÅÕ½Ðì¤ôØQ¡¸á¥Ð)]¹ Edited June 30, 2006 by PsaltyDS 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 More sharing options...
taurus905 Posted June 30, 2006 Share Posted June 30, 2006 Also, if you're only interested in one of the possible answers, you can get it in a single line with the MsgBox() statement: While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then If MsgBox(4+256, "Exit this program?", "Are you sure you want to quit?") = 6 Then Exit EndIf WEndoÝ÷ Øýz-¢vwhÂÆèƸ ÙèÂÊßÙe«Þ¶kÊ+ej׫nëb¶;¬¶º·¶¶Ù¢^½é𢹱«¢+Ù]¡¥±Ä($ÀÌØíµÍôU%Ñ5Í ¤(%%ÀÌØíµÍôÀÌØíU%}Y9Q} 1=MQ¡¸%5Í ½à ЬÈÔØ°ÅÕ½Ðíá¥ÐÑ¡¥ÌÁɽɴüÅÕ½Ðì°ÅÕ½ÐíÉå½ÔÍÕÉå½ÔݹÐѼÅÕ¥ÐüÅÕ½Ðì¤ôØQ¡¸á¥Ð)]¹ PsaltyDS, Your first example worked fine. I am not sure why I included the 'cancel' option in my example. But your second example produced an error: This keyword (Exit) cannot be used after a "Then" keyword. Just FYI. taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 30, 2006 Share Posted June 30, 2006 PsaltyDS, Your first example worked fine. I am not sure why I included the 'cancel' option in my example. But your second example produced an error: This keyword (Exit) cannot be used after a "Then" keyword. Just FYI. taurus905 I was not on a Windows box before and was coding off the top of my head. Just tested it and got the same error, but this worked: #include <GuiConstants.au3> GUICreate("Testing nested If's") GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE And MsgBox(4+256, "Exit?", "Exit program?") = 6 Then Exit WEnd Cheers! 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 More sharing options...
taurus905 Posted June 30, 2006 Share Posted June 30, 2006 I was not on a Windows box before and was coding off the top of my head. Just tested it and got the same error, but this worked: #include <GuiConstants.au3> GUICreate("Testing nested If's") GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE And MsgBox(4+256, "Exit?", "Exit program?") = 6 Then Exit WEnd Cheers! PsaltyDS, That's short and sweet. I like it. I think in my first example I spread it out so new users could better see what was going on and how easy it was to change in order to see the effect. But I would use your example in my scripts. Thanks, taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 30, 2006 Share Posted June 30, 2006 PsaltyDS, That's short and sweet. I like it. I think in my first example I spread it out so new users could better see what was going on and how easy it was to change in order to see the effect. But I would use your example in my scripts. Thanks, taurus905 I've only been using AutoIT about six months, so my code is NOT generally very tight. I only comment on other people's code this way as a tutorial exercise that is helping me strengthen my AutoIT-fu. Just for giggles, here's a further reduction in code: GUICreate("Testing Conditional Close") GUISetState() While 1 If GUIGetMsg() = -3 And MsgBox(4+256, "Exit?", "Exit program?") = 6 Then Exit WEnd Gets rid of the #include by explicitly using the value for $GUI_EVENT_CLOSE and doesn't bother saving $msg. I don't think it can be done any shorter than that! 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 More sharing options...
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