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

From Apache OpenOffice Wiki
Jump to: navigation, search
(Displaying Messages: + built-in tags for param values)
Line 17: Line 17:
 
</source>
 
</source>
  
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.
 +
{{Documentation/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.
Line 43: Line 45:
 
<source lang="oobas">
 
<source lang="oobas">
 
MsgBox "Do you want to continue?",  292
 
MsgBox "Do you want to continue?",  292
 +
' or,
 +
MsgBox "Do you want to continue?", MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION
 
</source>
 
</source>
  
 
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">
 
<source 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

Revision as of 21:30, 28 February 2009


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. Template:Documentation/Note 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

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")

As a return value, the InputBox provides the string typed by the user.


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