Jump to content

Message box button confusion


Guest Guest_Brett
 Share

Recommended Posts

Guest Guest_Brett

Can someone please help me out here. The documentation on the MsgBox command confuses me.

I have displayed a message box using this construct:

msgbox (65 , "My wonderful app", "Click here to receive $1 million") :huh2:

This displays an "i" message box with two buttons: OK and Cancel.

I now want to test if the Cancel button is clicked. The AutoIt documentation says "Success: Returns the ID of the button pressed" and that a value of 2 indicates the Cancel button is clicked.

So I test for "@error = 2" and the test fails when the Cancel button is clicked. So what should I test be for the Cancel button? Thanks. :D

Link to comment
Share on other sites

The return of a function is not the same as the @error macro. When you want to use the return of something, you need to either use it in an expression, or store the result to a variable. Like this:

$result = MsgBox(65, "Title", "Pick a button below...")
If $result = 1 Then ;the user hit OK, so tell them:
  MsgBox(0, "OK Pressed", "You pressed the OK button")
Else ;otherwise, they hit cancel
  MsgBox(0, "CANCEL Pressed", "You pressed the CANCEL button")
EndIf

Fixed my BB code

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

Guest Guest_Brett

Many thanks. Yes, that worked. Here's hoping someone will fix the AutoIt documentation to make this point clearer so that others won't be equally puzzled too.

Link to comment
Share on other sites

Here's hoping someone will fix the AutoIt documentation to make this point clearer so that others won't be equally puzzled too.

I think it's pretty clear as it's written. Each function uses the @error macro and the return value differently. Not all functions use both, and often you will only get a return value. If you look up the MsgBox function in the helpfile, it says nothing about the state of the @error macro. However, it does list what the return value will be. If you see the InputBox function, it lists both the return value, and the @error macro for various error cases (as an example of what to look for when you do want to use it.)

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

Many thanks.  Yes, that worked.  Here's hoping someone will fix the AutoIt documentation to make this point clearer so that others won't be equally puzzled too.

it's pretty obvious when your read about the @error macro, which tells you to look at SetError, which says:

The @error code is only valid until the next function is called. Consequently, you may need to backup the status of @error in a variable if you are testing it in a While-WEnd loop.

I don't blame the writers of aircraft mechanics manuals because I can't repair planes.

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

I think it's pretty clear as it's written. Each function uses the @error macro and the return value differently. Not all functions use both, and often you will only get a return value. If you look up the MsgBox function in the helpfile, it says nothing about the state of the @error macro. However, it does list what the return value will be. If you see the InputBox function, it lists both the return value, and the @error macro for various error cases (as an example of what to look for when you do want to use it.) As I mentioned in an earlier post

the $return-=Msgbox(blah) is not clear Jon himself had to tell me how to do it in yahoo group

This from a newbie (me) point of view

Rick

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...