MsgBox, InputBox focus unpredictability

LO Version: 6.1.5.2
mike@RPI4b2:~> uname -a
Linux MikesPI 5.10.11-v7l+ #1399 SMP Thu Jan 28 12:09:48 GMT 2021 armv7l GNU/Linux

In exploring LO, I’ve found it convenient to do something in basic then put up a MsgBox saying ‘I did this’ then doing something else and put up a MsgBox saying ‘I did that’, etc.

Typically I’m using MsgBox like this:

If(Msgbox( msg$, MB_OKCANCEL + MB_DEFBUTTON1, title$) <> IDOK) Then Stop

Whether the MsgBox and especially it’s ‘OK’ button has focus seems to be random and I’m having trouble understanding why or how to be sure that a simple return will let the process continue rather than having to select with the mouse.

The same situation is true of the InputBox, one time the input line will be selected, the next time even the box will not have focus. Sometimes entering in the input and hitting return will be accepted, others the OK button must be selected with the mouse.

I’m hoping someone can tell me how to make these boxes predictable.

Thanks, Mike

sample.ods

Here’s what you asked for Zizi64.
From your question should I assume you don’t see the same in your installation of LO?

Thanks, Mike

Please upload your sample file with the embedded sample macro, and please give us some more informations: which LO version are you using on what operating system?

Thank you for the sample file.

Your macro and the MsgBox works (as you expected it) in my LO6.1.6 on Windows10x64 Prof.
Always the first (the “OK”) button is selected (is focused) on the appearing MsgBox.


However I noticed a strange(?) thing in the Help:
There is NOT name of the constant of the “first button as default” parameter. Maybe you must use the numeric constant value (128) in the command on the Linux version.

See my attached image at my ANSWER.

Maybe you must use the numeric constant value (128) in the command on the Linux version.

No, the numeric value for MB_DEFBUTTON1 is 0, so even if it were undefined (which is not the case), it would make no difference. However, there’s a broken documentation - which is a bug worth filing.

FTR: MsgBox implementation.

Works for me with the numeric constant 128 too.

However the code

Option explicit

Function PrintValue()
	Print MB_DEFBUTTON1

End function

not throw me any error message, and that means: the variable IS defined somewhere.

Works for me with the numeric constant 128 too

Of course, since bit 7 is not checked in the code :slight_smile:

I meant the named variable under the Option Explicit directive int he sample code. The variable name MB_DEFBUTTON1 must be defined somewhere (it exists) in the code of the LO (but not in my code).

Yes I see in your attached code: it is not cheched.

I noticed a strange(?) thing in the Help: There is NOT name of the constant of the “first button as default” parameter neither in the LO616 Hungarian local Help nor is the online Help of the LO 7.1.x.

The documentation for the Msgbox function states that the function has named parameters Text, Type, Dialogtitle. In fact, the parameters have the same names as in Excel:

Msgbox Prompt:="Accident", Buttons:=MB_ICONSTOP, Title:="Documentation"

Of course you can use the combined numeric value (the sum) of the parameters related to the Buttons, Icons and the Default button number.

I got my definitions from here:
OO basic Guide

After spending half an hour stripping out inappropriate stuff from what I’m working on in order to send you a file, I realized in the middle of the night I should have posted this instead:

Sub mbLoop
	initMsg = "Message Number "
	i = 1
	Do
		msg$ = initMsg & i
	  	If(Msgbox( msg$, MB_OKCANCEL + MB_DEFBUTTON1, "mbLoop") <> IDOK) Then Stop
	  	i = i + 1
	Loop	
End Sub

Sub ibLoop
	default$ = "Boo"
	Do
		msg$ = initMsg & i
		default = InputBox("Please enter value:", "ibLoop", default)
	  	If(default = "") Then Stop
	Loop	
End Sub

This would have been much simpler had I thought of it at the time, getting senile perhaps.

In spite of all this conversation I see no answer to the question:

Is there a way to control this or must I learn how to write my own versions ?

Thanks,
Mike

Pressing Enter

image description

Version: 7.1.2.2 (x64) / LibreOffice Community
Build ID: 8a45595d069ef5570103caea1b71cc9d82b2aae4
CPU threads: 12; OS: Windows 10.0 Build 19042; UI render: Skia/Raster; VCL: win
Locale: ru-RU (ru_RU); UI: en-US
Calc: CL

Not sure how to read this Mike.

Are you saying that you got 432 MsgBoxes in a row that the OK button had the focus in LO V7.1.2.2?

If that’s so that’s good news and I thank you.

By any chance Is the InputBox also fixed? I’m using it in a DIY menu routine and continually having to click the text box then the OK button.

Be well,
Mike McClain

Not sure how to read this Mike.

Well, I’m saying that I only pressed Enter. That just means that your code created 432 dialog boxes in a row, which - reading your code - implies that the 431 key presses activated OK. Which - yes - basically means that “I got 432 MsgBoxes in a row that the OK button had the focus in LO V7.1.2.2”.

And InputBox also works fine here.

And I also tested 6.1.0.3 and 6.2.0.3 on Windows, and lost patience after 300+ MsgBoxes in a row. And that may indicate something platform-specific. You didn’t provide correct full info from Help->About, where e.g. a VCL plugin is mentioned; it could e.g. be specific to GTK plugin (which uses a different weld implementation compared to all other VCL plugins).

You’re right, my apologies:
Version: 6.1.5.2
Build ID: 1:6.1.5-3+rpi1+deb10u6+rpt1
CPU threads: 4; OS: Linux 5.10; UI render: default; VCL: x11;
Locale: en-US (en_US.UTF-8); Calc: group threaded

And In my system I can’t get 10 in a row, usually no more that 3.

Thanks for the info.
Mike

And yes I just checked, my system used libgtk, etc.
Thanks again,
Mike