[Solved] Detect mouse press in msgbox

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
kevinT220
Posts: 11
Joined: Wed Nov 18, 2020 5:43 am

[Solved] Detect mouse press in msgbox

Post by kevinT220 »

Im new to Javascript . Sry if i asking a stupid question.
I used msgbox to display an error message , in the boxmsg got a yes button, how i can only allow mouse press at yes button, then the msgbox only close.
i find one coding is something like com.sun.star.awt.MouseButton.LEFT but i dk how to add in.
Last edited by kevinT220 on Mon Dec 07, 2020 7:42 am, edited 2 times in total.
Apache OpenOffice4.1.7
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Detect mouse press in msgbox

Post by Zizi64 »

You can use the MsgBox as a function. The return value is an integer number: it show you which button was pushed (by a mouse click). See it in the Help.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: Detect mouse press in msgbox

Post by JeJe »

You can choose which buttons to show and only have an OK button if you wish. This is from the help file for BASIC,
MsgBox Function [Runtime]
Displays a dialog box containing a message and returns a value.
Syntax:
MsgBox (Text As String [,Type As Integer [,Dialogtitle As String]])
Return value:
Integer
Parameter:
Text: String expression displayed as a message in the dialog box. Line breaks can be inserted with Chr$(13).
DialogTitle: String expression displayed in the title bar of the dialog. If omitted, the name of the respective application is displayed.
Type: Any integer expression that specifies the dialog type and defines the number and type of buttons or icons displayed. Type represents a combination of bit patterns (dialog elements defined by adding the respective values):
Values
0 : Display OK button only.
1 : Display OK and Cancel buttons.
2 : Display Abort, Retry, and Ignore buttons.
3 : Display Yes, No, and Cancel buttons.
4 : Display Yes and No buttons.
5 : Display Retry and Cancel buttons.
16 : Add the Stop icon to the dialog.
32 : Add the Question icon to the dialog.
48 : Add the Exclamation Point icon to the dialog.
64 : Add the Information icon to the dialog.
128 : First button in the dialog as default button.
256 : Second button in the dialog as default button.
512 : Third button in the dialog as default button.
Return value:
1 : OK
2 : Cancel
3 : Abort
4 : Retry
5 : Ignore
6 : Yes
7 : No
Error Codes
5 Invalid procedure call
Example:
Sub ExampleMsgBox
Dim sVar as Integer
sVar = MsgBox("Las Vegas")
sVar = MsgBox("Las Vegas",1)
sVar = MsgBox( "Las Vegas",256 + 16 + 2,"Dialog title")
end sub
Edit: Javascript appears to have an OK only choice as well

https://www.w3schools.com/js/js_popup.asp
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
kevinT220
Posts: 11
Joined: Wed Nov 18, 2020 5:43 am

Re: Detect mouse press in msgbox

Post by kevinT220 »

can i set no default button on MsgBox?
Apache OpenOffice4.1.7
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: Detect mouse press in msgbox

Post by JeJe »

If you create your own dialog you can do whatever you want with it. All a MsgBox is is a dialog with a couple of buttons.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply