Jump to content

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


Recommended Posts

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")

Link to comment
Share on other sites

  • Moderators

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()

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...