Jump to content
Sign in to follow this  
pcvodak

How To Tell Which Button Is Clicked In A Yes/no Msgbox

Recommended Posts

pcvodak

I'm trying to figure out how to tell which button is clicked in a Yes/No MsgBox.

I want some code to execute when the user clicks the Yes button.

I already have a Gui running with other buttons on it and so I'm using a MsgBox.

MsgBox(4, "Yes/No" "Some question the user needs to answer")

Share this post


Link to post
Share on other sites
big_daddy

I'm trying to figure out how to tell which button is clicked in a Yes/No MsgBox.

I want some code to execute when the user clicks the Yes button.

I already have a Gui running with other buttons on it and so I'm using a MsgBox.

MsgBox(4, "Yes/No" "Some question the user needs to answer")

First you need to assign a variable to the msgbox, like so:

$var = MsgBox(4, "Yes/No" "Some question the user needs to answer")

Then after the msgbox check the return value, like so:

If $var = 1 Then
    MsgBox(0, "", 'You clicked "OK".')
ElseIf $var = 2 Then
    MsgBox(0, "", 'You clicked "Cancel".')
EndIf

More return values can be found in the help file under MsgBox()

Share this post


Link to post
Share on other sites
SmOke_N

First you need to assign a variable to the msgbox, like so:

$var = MsgBox(4, "Yes/No" "Some question the user needs to answer")

Then after the msgbox check the return value, like so:

If $var = 1 Then
    MsgBox(0, "", 'You clicked "OK".')
ElseIf $var = 2 Then
    MsgBox(0, "", 'You clicked "Cancel".')
EndIf

More return values can be found in the help file under MsgBox()

Just a side note, you don't need to store them in a variable if you are going to do an action right after based on whether one of the conditions are true or not.

Example:

If MsgBox(1, 'Info:', 'Just a test') = 1 Then
    MsgBox(0, "", 'You clicked "OK".')
Else
    MsgBox(0, "", 'You clicked "Cancel".')
EndIf

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.