MsgBox Function

Displays message box showing the String passed. With the exception of simple message boxes, you should use the MessageDialog class instead.

Syntax
result = MsgBox( message, [buttons], [title] )

Parameters
message | String | Any valid String expression. This parameter contains the main message of the dialog. If a paragraph break exists in the message, the second and following paragraphs will be de-emphasized on the Macintosh. They appear in the same font size on other platforms.
buttons | Integer (Optional) | Optional code indicating the icon and choice of buttons displayed in the Message box. You must handle the result if you pass a value for buttons.
title | String (Optional) | Optional text displayed in the Title bar (Windows and Linux). Title is not displayed on Macintosh. If you want to specify a value for Title, you must handle the result of the MsgBox call and also pass a value for button.

Return Value
Result | Integer | Indicates which button was pressed. It returns 1 if the OK button is clicked. If you don't use the optional parameters, MsgBox can be called without handling result. 1 - OK Pressed 2 - Cancel Pressed 3 - Abort pressed 4 - Retry pressed 5 - Ignore pressed 6 - Yes pressed 7 - No pressed

# Notes

)

A message can be presented to the user with either the MsgBox function or the MessageDialog class. The MsgBox function is recommended for simple informational messages only. For other situations, the MessageDialog class is more appropriate. It enables you to add up to three buttons, label them in any way, and take any action after the user clicked a button. MsgBox is also ideally suited for porting VisualBasic programs to REALbasic.

The Message box opened by MsgBox has a Title bar. On Windows, the dialog also has a Close widget in its Title bar. The dialog can be closed either by clicking OK or clicking the Close widget. On Windows and Linux, the width increases to accommodate the longest paragraph. On Macintosh, the Message box has a fixed width and the text word-wraps to fit the width of the MsgBox.

Multiple paragraphs can be passed in the message parameter by separating each paragraph with the EndOfLine function.

## The Buttons Parameter

Buttons is an optional parameter that enables you to customize the buttons and icon displayed in the message box to a limited extent. You get a fixed choice of button text and button positions. The value of Buttons is the sum of values that describe the number and labelling of the buttons, the icon, and the default button.There are three groups of button values; each group offers choices for a particular feature.

Value | Description
--- | ---
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 only.
5 | Display Retry and Cancel buttons.

The second group of values specifies the icon to be displayed.

Value | Description
--- | ---
0 | No icon.
16 | Stop sign icon.
32 | Question icon.
48 | Caution triangle icon.
64 | Note Icon.

The third group of values pertains to the selection of the default button. The terms first, second, and third in the following table do not necessarily refer to the physical positions of the buttons, which may vary among platforms. It refers to the ordering in the Group 1 table.

Value | Description
--- | ---
0 | First button of Group 1 list is the default.
256 | Second button of Group 1 list is the default.
512 | Third button of Group 1 list is the default.
768 | No button is the default.

Since the value of the button parameter is the sum, you make a selection from each of the three tables, add up their values and pass that value. For example, if you want the buttons to be the "Abort, Retry, and Ignore" set, with a Caution icon, and Retry as the default, you would add up 2 + 48 + 256 = 306. This also illustrates why you should be using the MessageDialog class for a message dialog such as this. In contrast, the MessageDialog class allows you to set button text to any string and set the default property via a Boolean property.

# Examples

This example displays a one line Message box.

MsgBox "Hello World."

The following example uses the EndOfLine function to break text to be displayed in a MsgBox into two paragraphs. When you use EndOfLine in this way, the second line will be de-emphasized relative to the first (Macintosh only).

MsgBox "Hello world"+ EndOfLine+ EndOfLine+"Such as it is"

The following example displays a multiline Message box. The text after the two EndOfLine functions appears in plain type and a smaller font size on Macintosh. On other platforms, the second paragraph appears in the same font size and style as the first. Please note that it is entered as one line in the Code Editor.

MsgBox "Please enter all your credit card info, bank accounts, and trust funds before proceeding to run my shareware application."+ EndOfLine+EndOfLine+"Any additional voluntary contributions are gratefully accepted."

This example displays a Message box with "Yes" and "No" buttons.

Dim n as Integer
n=MsgBox("Do you want to rebuild this mailbox",36)
If n=6 then
//user pressed Yes
elseif n=7 then
//user pressed No
end if

# See Also

EndOfLine, MessageDialog, MessageDialogButton classes.