Jump to content
Sign in to follow this  
crz

Please don't laugh! :)

Recommended Posts

crz

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 by crz

Steffen "crz" Jorgensenwww.crz.dkcrz@crz.dk

Share this post


Link to post
Share on other sites
McDope

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 :D

Edited by McDope

Share this post


Link to post
Share on other sites
taurus905

crz,

Welcome to the AutoIt forum. :D

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

"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

Share this post


Link to post
Share on other sites
crz

Awesome, just what I needed.

Thanks.


Steffen "crz" Jorgensenwww.crz.dkcrz@crz.dk

Share this post


Link to post
Share on other sites
PsaltyDS

crz,

Welcome to the AutoIt forum. :D

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¡¸á¥Ð)]¹

:wacko:

Edited 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

Share this post


Link to post
Share on other sites
taurus905

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¡¸á¥Ð)]¹

:wacko:

PsaltyDS,

Your first example worked fine. I am not sure why I included the 'cancel' option in my example. :D

But your second example produced an error:

This keyword (Exit) cannot be used after a "Then" keyword.

Just FYI. :D

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

Share this post


Link to post
Share on other sites
PsaltyDS

PsaltyDS,

Your first example worked fine. I am not sure why I included the 'cancel' option in my example. :D

But your second example produced an error:

This keyword (Exit) cannot be used after a "Then" keyword.

Just FYI. :wacko:

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! :D


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
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! :D

PsaltyDS,

That's short and sweet. I like it. :wacko:

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

Share this post


Link to post
Share on other sites
PsaltyDS

PsaltyDS,

That's short and sweet. I like it. :wacko:

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!

:D


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

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  

×