Difference between revisions of "Documentation/BASIC Guide/Message and Input Boxes (Runtime Library)"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:Message and Input Boxes ({{OOo}} Runtime Library)}}
+
{{DISPLAYTITLE:Message and Input Boxes ({{AOo}} Runtime Library)}}
 
{{Documentation/BASICGuideTOC/v2
 
{{Documentation/BASICGuideTOC/v2
 
|ShowPrevNext=block
 
|ShowPrevNext=block
Line 8: Line 8:
 
}}
 
}}
 
   
 
   
{{OOo}} Basic provides the <tt>MsgBox</tt> and <tt>InputBox</tt> functions for basic user communication.
+
{{AOo}} Basic provides the <tt>MsgBox</tt> and <tt>InputBox</tt> functions for basic user communication.
  
 
== Displaying Messages ==
 
== Displaying Messages ==
 
<tt>MsgBox</tt> displays a basic information box, which can have one or more buttons. In its simplest variant the <tt>MsgBox</tt> only contains text and an OK button:
 
<tt>MsgBox</tt> displays a basic information box, which can have one or more buttons. In its simplest variant the <tt>MsgBox</tt> only contains text and an OK button:
  
<source lang="oobas">
+
<syntaxhighlight lang="oobas">
 
MsgBox "This is a piece of information!"
 
MsgBox "This is a piece of information!"
</source>
+
</syntaxhighlight>
  
The appearance of the information box can be changed using a parameter. The parameter provides the option of adding additional buttons, defining the pre-assigned button, and adding an information symbol. The values for selecting the buttons are:  
+
The appearance of the information box can be changed using a parameter. The parameter provides the option of adding additional buttons, defining the pre-assigned button, and adding an information symbol.
 +
{{Note|By convention, the symbolic names given below are written in UPPERCASE, to mark them as predefined, rather than user-defined. However, the names are not case-sensitive.}}
 +
The values for selecting the buttons are:  
  
* <tt>0</tt> - OK button
+
* <tt>0, MB_OK</tt> - OK button
* <tt>1</tt> - OK and Cancel button
+
* <tt>1, MB_OKCANCEL</tt> - OK and Cancel button
* <tt>2</tt> - Abort, Retry, and Ignore buttons  
+
* <tt>2, MB_ABORTRETRYIGNORE</tt> - Abort, Retry, and Ignore buttons  
* <tt>3</tt> - Yes, No, and Cancel buttons
+
* <tt>3, MB_YESNOCANCEL</tt> - Yes, No, and Cancel buttons
* <tt>4</tt> - Yes and No buttons
+
* <tt>4, MB_YESNO</tt> - Yes and No buttons
* <tt>5</tt> - Retry and Cancel buttons
+
* <tt>5, MB_RETRYCANCEL</tt> - Retry and Cancel buttons
  
To set a button as the default button, add one of the following values to the parameter value from the list of button selections. For example, to create Yes, No and Cancel buttons (value 3) where Cancel is the default (value 512), the parameter value is 3 + 512 = 515.  
+
To set a button as the default button, add one of the following values to the parameter value from the list of button selections. For example, to create Yes, No and Cancel buttons (value 3) where Cancel is the default (value 512), the parameter value is 3 + 512 = 515. The expression <tt>MB_YESNOCANCEL + MB_DEFBUTTON3</tt> is harder to write, but easier to understand.
  
* <tt>0</tt> - First button is default value
+
* <tt>0, MB_DEFBUTTON1</tt> - First button is default value
* <tt>256</tt> - Second button is default value  
+
* <tt>256, MB_DEFBUTTON2</tt> - Second button is default value  
* <tt>512</tt> - Third button is default value
+
* <tt>512, MB_DEFBUTTON3</tt> - Third button is default value
  
 
Finally, the following information symbols are available and can also be displayed by adding the relevant parameter values:  
 
Finally, the following information symbols are available and can also be displayed by adding the relevant parameter values:  
  
* <tt>16</tt> - Stop sign
+
* <tt>16, MB_ICONSTOP</tt> - Stop sign
* <tt>32</tt> - Question mark  
+
* <tt>32, MB_ICONQUESTION</tt> - Question mark  
* <tt>48</tt> - Exclamation point
+
* <tt>48, MB_ICONEXCLAMATION</tt> - Exclamation point
* <tt>64</tt> - Tip icon
+
* <tt>64, MB_ICONINFORMATION</tt> - Tip icon
  
 
The following call displays an information box with the Yes and No buttons (value 4), of which the second button (No) is set as the default value (value 256) and which also receives a question mark (value 32), 4+256+32=292.
 
The following call displays an information box with the Yes and No buttons (value 4), of which the second button (No) is set as the default value (value 256) and which also receives a question mark (value 32), 4+256+32=292.
  
<source lang="oobas">
+
<syntaxhighlight lang="oobas">
 
MsgBox "Do you want to continue?",  292
 
MsgBox "Do you want to continue?",  292
</source>
+
' or,
 +
MsgBox "Do you want to continue?", MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION
 +
</syntaxhighlight>
 +
[[Image:MsgBox292.png|300px|none|thumb|Display of the Message Box]]
  
 
If an information box contains several buttons, then a return value should be queried to determine which button has been pressed. The following return values are available in this instance:
 
If an information box contains several buttons, then a return value should be queried to determine which button has been pressed. The following return values are available in this instance:
  
* <tt>1</tt> - Ok  
+
* <tt>1, IDOK</tt> - Ok  
* <tt>2</tt> - Cancel
+
* <tt>2, IDCANCEL</tt> - Cancel
* <tt>3</tt> - Abort
+
* <tt>3, IDABORT</tt> - Abort
* <tt>4</tt> - Retry
+
* <tt>4, IDRETRY</tt> - Retry
 
* <tt>5</tt> - Ignore
 
* <tt>5</tt> - Ignore
* <tt>6</tt> - Yes
+
* <tt>6, IDYES</tt> - Yes
* <tt>7</tt> - No  
+
* <tt>7, IDNO</tt> - No  
  
 
In the previous example, checking the return values could be as follows:  
 
In the previous example, checking the return values could be as follows:  
  
<source lang="oobas">
+
<syntaxhighlight lang="oobas">
 +
Dim iBox as Integer
 +
iBox = MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION
 +
If MsgBox ("Do you want to continue?", iBox) = IDYES Then
 +
' or,
 
If MsgBox ("Do you want to continue?",  292) = 6 Then
 
If MsgBox ("Do you want to continue?",  292) = 6 Then
 
   ' Yes button pressed
 
   ' Yes button pressed
Line 63: Line 72:
 
   ' No button pressed
 
   ' No button pressed
 
End IF
 
End IF
</source>
+
</syntaxhighlight>
  
 
In addition to the information text and the parameter for arranging the information box, <tt>MsgBox</tt> also permits a third parameter, which defines the text for the box title:
 
In addition to the information text and the parameter for arranging the information box, <tt>MsgBox</tt> also permits a third parameter, which defines the text for the box title:
  
<source lang="oobas">
+
<syntaxhighlight lang="oobas">
 
MsgBox "Do you want to continue?",  292, "Box Title"
 
MsgBox "Do you want to continue?",  292, "Box Title"
</source>
+
</syntaxhighlight>
  
 
If no box title is specified, the default is “soffice”.
 
If no box title is specified, the default is “soffice”.
Line 81: Line 90:
 
* A default value which can be added within the input area.
 
* A default value which can be added within the input area.
  
<source lang="oobas">
+
<syntaxhighlight lang="oobas">
 
InputVal = InputBox("Please enter value:", "Test", "default value")
 
InputVal = InputBox("Please enter value:", "Test", "default value")
</source>
+
</syntaxhighlight>
  
As a return value, the <tt>InputBox</tt> provides the string typed by the user.  
+
[[Image:InputBoxTest.png|600px|none|thumb|Display of the Input Box]]
 +
 
 +
* The dimensions of the <tt>InputBox</tt> window cannot be changed.
 +
* If the user clicks the OK button, the <tt>InputBox</tt> returns the string typed by the user (or the default string if it was not changed).
 +
* If the user clicks the Cancel button or closes the window, the <tt>InputBox</tt> returns an empty string.
  
 
   
 
   
 
{{InterWiki Languages BasicGuide|articletitle=Documentation/BASIC Guide/Message and Input Boxes (Runtime Library)}}
 
{{InterWiki Languages BasicGuide|articletitle=Documentation/BASIC Guide/Message and Input Boxes (Runtime Library)}}
 
{{PDL1}}
 
{{PDL1}}

Latest revision as of 12:14, 30 January 2021


Apache OpenOffice Basic provides the MsgBox and InputBox functions for basic user communication.

Displaying Messages

MsgBox displays a basic information box, which can have one or more buttons. In its simplest variant the MsgBox only contains text and an OK button:

MsgBox "This is a piece of information!"

The appearance of the information box can be changed using a parameter. The parameter provides the option of adding additional buttons, defining the pre-assigned button, and adding an information symbol.

Documentation note.png By convention, the symbolic names given below are written in UPPERCASE, to mark them as predefined, rather than user-defined. However, the names are not case-sensitive.

The values for selecting the buttons are:

  • 0, MB_OK - OK button
  • 1, MB_OKCANCEL - OK and Cancel button
  • 2, MB_ABORTRETRYIGNORE - Abort, Retry, and Ignore buttons
  • 3, MB_YESNOCANCEL - Yes, No, and Cancel buttons
  • 4, MB_YESNO - Yes and No buttons
  • 5, MB_RETRYCANCEL - Retry and Cancel buttons

To set a button as the default button, add one of the following values to the parameter value from the list of button selections. For example, to create Yes, No and Cancel buttons (value 3) where Cancel is the default (value 512), the parameter value is 3 + 512 = 515. The expression MB_YESNOCANCEL + MB_DEFBUTTON3 is harder to write, but easier to understand.

  • 0, MB_DEFBUTTON1 - First button is default value
  • 256, MB_DEFBUTTON2 - Second button is default value
  • 512, MB_DEFBUTTON3 - Third button is default value

Finally, the following information symbols are available and can also be displayed by adding the relevant parameter values:

  • 16, MB_ICONSTOP - Stop sign
  • 32, MB_ICONQUESTION - Question mark
  • 48, MB_ICONEXCLAMATION - Exclamation point
  • 64, MB_ICONINFORMATION - Tip icon

The following call displays an information box with the Yes and No buttons (value 4), of which the second button (No) is set as the default value (value 256) and which also receives a question mark (value 32), 4+256+32=292.

MsgBox "Do you want to continue?",  292
' or,
MsgBox "Do you want to continue?", MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION
Display of the Message Box

If an information box contains several buttons, then a return value should be queried to determine which button has been pressed. The following return values are available in this instance:

  • 1, IDOK - Ok
  • 2, IDCANCEL - Cancel
  • 3, IDABORT - Abort
  • 4, IDRETRY - Retry
  • 5 - Ignore
  • 6, IDYES - Yes
  • 7, IDNO - No

In the previous example, checking the return values could be as follows:

Dim iBox as Integer
iBox = MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION
If MsgBox ("Do you want to continue?", iBox) = IDYES Then
' or,
If MsgBox ("Do you want to continue?",  292) = 6 Then
  ' Yes button pressed
Else
  ' No button pressed
End IF

In addition to the information text and the parameter for arranging the information box, MsgBox also permits a third parameter, which defines the text for the box title:

MsgBox "Do you want to continue?",  292, "Box Title"

If no box title is specified, the default is “soffice”.

Input Box For Querying Simple Strings

The InputBox function queries simple strings from the user. It is therefore a simple alternative to configuring dialogs. InputBox receives three standard parameters:

  • An information text.
  • A box title.
  • A default value which can be added within the input area.
InputVal = InputBox("Please enter value:", "Test", "default value")
Display of the Input Box
  • The dimensions of the InputBox window cannot be changed.
  • If the user clicks the OK button, the InputBox returns the string typed by the user (or the default string if it was not changed).
  • If the user clicks the Cancel button or closes the window, the InputBox returns an empty string.


Content on this page is licensed under the Public Documentation License (PDL).
Personal tools