possible issue: MsgBox: omit first parameter Topic is solved

Discuss the future of the AutoHotkey language
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

possible issue: MsgBox: omit first parameter

17 Mar 2018, 19:23

Is this to be expected? I might have expected omitting the first parameter to give 'Press OK to continue.', and perhaps it would be desirable, because if I wanted blank text, I could just specify "". Thanks.

Code: Select all

MsgBox() ;Press OK to continue.
MsgBox(,, "") ;(blank)
MsgBox
https://lexikos.github.io/v2/docs/commands/MsgBox.htm
If all the parameters are omitted, the MsgBox will display the text "Press OK to continue.".
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: possible issue: MsgBox: omit first parameter

18 Mar 2018, 04:30

Specifying an empty string is not 'omitting a parameter'.
coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: possible issue: MsgBox: omit first parameter

18 Mar 2018, 04:50

I think the problem is with

Code: Select all

Msgbox(,,)
Since that is supposedly omitting all parameters, or at least should be equivalent to Msgbox()
Msgbox(,,"") is not omitting all parameters.

The default value for omitting the text parameter is empty string when you are using the other parameters.

It seems Msgbox(,,) increments the parameter count of the function. It appears to be a small conflict with how (,,) is parsed, it's not really a problem with the Msgbox function itself, aside from its documentation not specifying the default value.
The macros seem to default to empty value, but they always confuse me a bit, so i'm not too sure.
This is a comment in source, which applies to how the text parameter is retrieved.
// The macro below defaults to "", since that is by far the most common default.
// This allows it to skip the check for SYM_MISSING, which always has marker == _T("").
Comment in source
When called explicitly with zero params, it displays this default msg.
For autohotkey
Msgbox() <- zero params
Msgbox(,,) <- not zero params

Adding

Code: Select all

		if (aText == _T(""))
			aText = _T("Press OK to continue.");
After

Code: Select all

_f_param_string_opt(aText, 0);
In BIF_DECL(BIF_MsgBox), seems to make Msgbox(,,) more consistent with Msgbox() as it shows "Press OK to continue." when you use Msgbox(,,). But it also changes Msgbox(,,"") to show the ok continue, which goes against what the documentation says.

The previous check is

Code: Select all

	if (!aParamCount) // When called explicitly with zero params, it displays this default msg.
	{
		result = MsgBox(_T("Press OK to continue."), MSGBOX_NORMAL, NULL, 0, dialog_owner);
	}
Where aParamCount is true for Msgbox(,,)
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: possible issue: MsgBox: omit first parameter

18 Mar 2018, 07:16

Hi coffee,

technically you're right, but I think that nobody would use

Code: Select all

MsgBox(,,)
by choice.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: possible issue: MsgBox: omit first parameter

18 Mar 2018, 07:37

The function obviously behaves as documented.
I might have expected omitting the first parameter to give 'Press OK to continue.', and perhaps it would be desirable, because if I wanted blank text, I could just specify "".
What would you expect from msgbox ,,2 :roll: ?

F(,,) is not relevant Imo, its behaviour or validity is not even documented as far as I know.

If there was a vote on changing something about the press OK to continue message, I'd vote to remove it and display blank instead. The message doesn't even match the text on the button for many non-English users.

Cheers.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: possible issue: MsgBox: omit first parameter

18 Mar 2018, 08:45

- The point is that these behave differently. Even though all parameters are omitted.

Code: Select all

MsgBox()
MsgBox(,,)
- Since many of the AHK v2 functions are based on commands, and the MsgBox command was particularly unusual, it wouldn't be surprising that something like this was a bug.
- The current behaviour breaks the principle of least astonishment/surprise, in my opinion it is very unusual, there is a Text parameter, whose behaviour should not be altered by the other parameters.
- @Helgef: In theory, there could be an option added to change the default MsgBox text.
- @Helgef: With the MsgBox command, you cannot distinguish between blank text and an omitted parameter.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: possible issue: MsgBox: omit first parameter

18 Mar 2018, 11:08

- The point is that these behave differently. Even though all parameters are omitted.
I think that was coffee's point, it makes more sense, but I argued against having any expectations on f(,,), with it not being defined.
The current behaviour breaks the principle of least astonishment/surprise
The only surprise is f(,,) not being an error.

@ jeeswg: sure.
@ jeeswg: that is correct, and irrelevant.

Cheers.
Edit: We have already touched the subject.
Trailing empty function parameters are not supported.
src
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: possible issue: MsgBox: omit first parameter

18 Mar 2018, 12:00

- I was in a bit of a dilemma recreating the MsgBox function twice, once for 'AHK v2 functions for AHK v1', and once for 'slightly-improved dialogs'. I discovered by accident, the surprising behaviour.
- Looking through the AHK source code seems like jumping the gun, until (probably) the functions are all redone in the BIF (built-in function) format.
- A parameter behaving differently based on the total number of parameters passed, seems odd, the sort of quirky AHK v1 behaviour I hoped we were getting rid of.
- @Helgef: Why did you bring up the AHK v1 MsgBox command? I was also surprised about f(,,) not being an error.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: possible issue: MsgBox: omit first parameter

18 Mar 2018, 13:23

Why did you bring up the AHK v1 MsgBox command?
I see you misunderstood, please let me try again, would you expect

Code: Select all

msgbox(,,2) ; Cancel, try again, ignore
to display the message Press OK to continue?

Cheers.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: possible issue: MsgBox: omit first parameter

18 Mar 2018, 16:37

I would
Recommends AHK Studio
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
Location: Middle of the round cube
Contact:

Re: possible issue: MsgBox: omit first parameter

18 Mar 2018, 17:07

but there is not OK button to press

So lets change the behaviour and the docs.
Unless the buttons are modified from the default, omitting the text parameter [no matter how many other parameters are omitted] will set the text to "Press OK to continue." If the buttons have been specified other than the default, [the text will be ""](or whatever it should be).
try it and see
...
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: possible issue: MsgBox: omit first parameter

18 Mar 2018, 17:13

Yes, yes I would. Thanks for agreeing nnnik. [Well done though Helgef, that's some good left-field thinking by you, to come up with that argument.]
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: possible issue: MsgBox: omit first parameter

19 Mar 2018, 09:06

I would simply make the default value for the text parameter "Press any Button to continue".
Recommends AHK Studio
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: possible issue: MsgBox: omit first parameter

20 Mar 2018, 13:58

that's some good left-field thinking
I disagree :morebeard:.
"Press any Button to continue".
It isn't suitable for any of the button options.
So lets change the behaviour and the docs.
That is very diplomatic ;).
I'd vote to remove it and display blank instead.
I agree :thumbup:.

Cheers.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: possible issue: MsgBox: omit first parameter

20 Mar 2018, 18:25

Helgef wrote:
"Press any Button to continue".
It isn't suitable for any of the button options.
Could you elaborate what you mean by that?
Recommends AHK Studio
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: possible issue: MsgBox: omit first parameter

21 Mar 2018, 13:47

If you have more than one button, it means you present the user with some options, then I say, Press any Button to continue, doesn't present the options very well. For the OK msgbox, if you consider the [X] button, I guess it is ok to say, any button.

Cheers.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: possible issue: MsgBox: omit first parameter

22 Mar 2018, 11:42

The text describes the consequence of pressing the buttons along with any additional information that might be given by the script.
By default even if you change which buttons are displayed nothing special happens other than continuing with execution.
Therefore the defult text can be "Press any Button to continue". If you change the default behaviour change the default text.
Keeping it empty is the only better solution I see.
Recommends AHK Studio
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: possible issue: MsgBox: omit first parameter

25 Mar 2018, 18:54

- I was caught between two conflicting principles:
- When the Text parameter is omitted, the MsgBox text should be blank.
- It's very useful that when 0 parameters are specified, there is some standard text.

- I think that the best solution is to do nothing. The current behaviour is a little bit quirky, but on balance, it is for the best.
- However, I think that this should be made clearer in the documentation, and it now features prominently on my documentation extension tutorial. 'MsgBox: in AHK v2, the Text parameter has two defaults, 'Press OK to continue.', for MsgBox(), and a blank string otherwise, e.g. MsgBox(,, "").'
- I will have to amend my AHK v2 MsgBox function for AHK v1 backport, and custom MsgBox function that I was working on.
- One possible change. In theory, there could be an option to change the 2 default texts, for 0 and/or 1-or-more parameters.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: possible issue: MsgBox: omit first parameter  Topic is solved

07 Apr 2018, 22:07

The behaviour of MsgBox(,, "") is expected.
The behaviour of f(,,) was fixed in v2.0-a090.
I do not intend to make any changes to MsgBox.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: possible issue: MsgBox: omit first parameter

08 Apr 2018, 13:50

lexikos wrote:The behaviour of f(,,) was fixed in v2.0-a090.
Exactly what was fixed? I considered these not being errors, erroneous,

Code: Select all

msgbox(,,)
f(,,)
f(p*){
}
I get no error message. (a093)

Cheers.

Edit: Even this isn't an error

Code: Select all

msgbox(,,,,,,,,,,,,,)
Edit 2:
coffee wrote:For autohotkey
Msgbox() <- zero params
Msgbox(,,) <- not zero params
I guess it was that.

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 33 guests