Jump to content

msgbox ? inconsistency.


bs27975
 Share

Recommended Posts

#include <MsgBoxConstants.au3>

global const $gsOurTitle = "Our Title"

Global Const $gcNumMonitors = 4

Local $lbDoScreens[$gcNumMonitors] = [True, False, False, False]

Local $ln1, $ln2

$ln1 = 0

$ln2 = ($lbDoScreens[$ln1] = True) ? ($MB_DEFBUTTON1) : ($MB_DEFBUTTON2)

$li1 = MsgBox($MB_YESNOCANCEL + $MB_ICONQUESTION + $MB_TOPMOST + $MB_TASKMODAL _
          + ($lbDoScreens[$ln1] = True) ? ($MB_DEFBUTTON1) : ($MB_DEFBUTTON2) _
          , $gsOurTitle, "Process Screen " & $ln1 & "?", 0)


$li1 = MsgBox($MB_YESNOCANCEL + $MB_ICONQUESTION + $MB_TOPMOST + $MB_TASKMODAL _
         + $ln2 _
         , $gsOurTitle, "Process Screen " & $ln1 & "?", 0)
 

<hr>

First msgbox() only has the single OK button.

Second msgbox() has the expected Yes, No, and Cancel, buttons.

FYI.

<hr>

$ln2 = ($lbDoScreens[$ln1] = True) ? ($MB_DEFBUTTON1) : ($MB_DEFBUTTON2)

could also be:

$ln2 = $lbDoScreens[$ln1] ? $MB_DEFBUTTON1 : $MB_DEFBUTTON2

Link to comment
Share on other sites

Do you have a question?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Care to explain what you think is the bug? Your post said nothing, just a script that doesn't really explain anything.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I THINK I figured out what you THINK is a bug, it's not it's just bad programming on your part. Try it this way.

#include <MsgBoxConstants.au3>

Global Const $gsOurTitle = "Our Title"

Global Const $gcNumMonitors = 4

Local $lbDoScreens[$gcNumMonitors] = [True, False, False, False]

Local $ln1, $ln2

$ln1 = 0

$ln2 = ($lbDoScreens[$ln1] = True) ? ($MB_DEFBUTTON2) : ($MB_DEFBUTTON1)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ln2 = ' & $ln2 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$li1 = MsgBox($MB_YESNOCANCEL + $MB_ICONQUESTION + $MB_TOPMOST + $MB_TASKMODAL _
         + (($lbDoScreens[$ln1] = True) ? ($MB_DEFBUTTON1) : ($MB_DEFBUTTON2)) _
        , $gsOurTitle, "Process Screen " & $ln1 & "?", 0)


$li1 = MsgBox($MB_YESNOCANCEL + $MB_ICONQUESTION + $MB_TOPMOST + $MB_TASKMODAL _
         + $ln2 _
        , $gsOurTitle, "Process Screen " & $ln1 & "?", 0)

I put parentheses around the ternary statement in the first message box line, where you had none, this allows it to be processed correctly.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

> Care to explain what you think is the bug? Your post said nothing, just a script that doesn't really explain anything.

>> First msgbox() only has the single OK button.
>>
>> Second msgbox() has the expected Yes, No, and Cancel, buttons.

Ergo, bug in processing of first msgbox call. Self-evidently, the two should behave the same.

>  just bad programming on your part

Oh, dear me, no.

That's quite correct, common, and reasonable programming. [Sans the extraneous ()'s put in per the below.]

However, I take your point. Parsing limitations.

Reflecting the help comment of: "Although not necessary in all cases, it is strongly recommended that the 3 elements are enclosed in parentheses." [Collectively, not individually as in the yellow box in help. Hmm. I see now even the example only brackets the logic test.]

Could the help file please be updated in 'Ternary' to change: "(expression) ? (expression1 if expression is True) : (expression2 if expression is False)" to "((expression) ? (expression1 if expression is True) : (expression2 if expression is False))", or even to "(expression ? expression1 if expression is True : expression2 if expression is False)" if appropriate. [Extra ()'s around entire.]

I only put the () around what I did because of that bit in the help. If I had put them as above, I would not have needed to write. [And you would not have needed to answer. :) ]

Thank you for the observation.


 

Link to comment
Share on other sites

If you want AutoIt to process a complex expression, you need to let the interpreter know what it is you want. Take for example these lines of code.

$I = 0
MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & 'Not $I = 1' & @CRLF & @CRLF & 'Return:' & @CRLF & Not $I = 1) ;### Debug MSGBOX
MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & '(Not $I = 1)' & @CRLF & @CRLF & 'Return:' & @CRLF & (Not $I = 1)) ;### Debug MSGBOX

Ignore the part where the Msgbox doesn't display correctly in the first example, the False throws it off, but you'll see that they're processed differently.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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