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

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Displaying Messages: fix MsgBox options)
Line 1: Line 1:
{{DISPLAYTITLE:Message and Input Boxes ({{OOo}} Runtime Library)}}
Line 5: Line 6:
|NextPage=Documentation/BASIC Guide/Other Functions (Runtime Library)
|NextPage=Documentation/BASIC Guide/Other Functions (Runtime Library)
}}<!-- {{DISPLAYTITLE:Message and Input Boxes ({{OOo}} Runtime Library) -->
= Message and Input Boxes =
{{OOo}} Basic provides the <tt>MsgBox</tt> and <tt>InputBox</tt> functions for basic user communication.
{{OOo}} Basic provides the <tt>MsgBox</tt> and <tt>InputBox</tt> functions for basic user communication.

Revision as of 17:59, 20 February 2008

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. The values for selecting the buttons are:

  • 0 - OK button
  • 1 - OK and Cancel button
  • 2 - Abort, Retry, and Ignore buttons
  • 3 - Yes, No, and Cancel buttons
  • 4 - Yes and No buttons
  • 5 - 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.

  • 0 - First button is default value
  • 256 - Second button is default value
  • 512 - Third button is default value

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

  • 16 - Stop sign
  • 32 - Question mark
  • 48 - Exclamation point
  • 64 - 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

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 - Ok
  • 2 - Cancel
  • 3 - Abort
  • 4 - Retry
  • 5 - Ignore
  • 6 - Yes
  • 7 - No

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

If MsgBox ("Do you want to continue?",  292) = 6 Then
  ' Yes button pressed
  ' 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