<div class="meta" robots="noindex">

</div>

Method

# MsgBox

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2019r2. Please use `MessageBox</api/user_interface/messagebox>` or `MessageDialog</api/user_interface/desktop/messagedialog>` as a replacement.

</div>

## Description

Displays message box showing the `string</api/data_types/string>` passed. With the exception of simple message boxes, you should use the `MessageDialog</api/user_interface/desktop/messagedialog>` class instead.

## Usage

**Web Apps**

**MsgBox**(*message*)

Displays *message* in a browser dialog with a single OK button.

**Console Apps**

**MsgBox**(*message*)

Works the same as `Print</api/console/print>`. The *message* is output to the console/terminal.

**Desktop Apps**

*result* = **MsgBox**(*message* \[,*buttons*\]\[,*title*\])

| Part    | Type                               | Description                                                                           |
|---------|------------------------------------|---------------------------------------------------------------------------------------|
| result  | `Integer</api/data_types/integer>` | Indicates which button was pressed.                                                   |
| message | `String</api/data_types/string>`   | Any valid `string</api/data_types/string>` expression.                                |
| buttons | `Integer</api/data_types/integer>` | Optional code indicating the icon and choice of buttons displayed in the Message box. |
| title   | `String</api/data_types/string>`   | Optional text displayed in the Title bar (Windows and Linux).                         |

## Notes

<div class="warning">

<div class="title">

Warning

</div>

<span class="title-ref">MsgBox</span> remains for Visual Basic (VB) compatibility-only. Instead use `MessageBox</api/user_interface/messagebox>`.

</div>

<div class="warning">

<div class="title">

Warning

</div>

You should avoid using <span class="title-ref">MsgBox</span> for displaying debugging messages. The displaying of the Message Box will alter event order and may give unexpected results. Instead use the `Debugger</getting_started/debugging/debugger_usage>`, `System.DebugLog<system.debuglog>` or your own logging mechanism.

</div>

A message can be presented to the user with either the <span class="title-ref">MsgBox</span> function or the `MessageDialog</api/user_interface/desktop/messagedialog>` class. The <span class="title-ref">MsgBox</span> function is recommended for simple informational messages only. For other situations, the `MessageDialog</api/user_interface/desktop/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. <span class="title-ref">MsgBox</span> is also ideally suited for porting VisualBasic programs to Xojo.

The Message box opened by <span class="title-ref">MsgBox</span> 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 <span class="title-ref">MsgBox</span>.

Multiple paragraphs can be passed in the message parameter by separating each paragraph with the `EndOfLine</api/text/endofline>` function.

Closing a <span class="title-ref">MsgBox</span> gives the focus back to the window, which calls its Activate event.

On macOS only the Caution icon is displayed. This is the result of changes made by Apple in HID specs. See [here](http://developer.apple.com/legacy/mac/library/qa/qa2004/qa1378.html) for details.

The <span class="title-ref">MsgBox</span> buttons are not localized — this is a known bug (feedback report 4665).

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### 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.

| roup 1: Number and Type of Buttons. | 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.

| roup 2: 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.

| roup 3: Selection of Default Button. | 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</api/user_interface/desktop/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</api/data_types/boolean>` property.

## Sample code

This code displays a one line Message box.

``` xojo
MsgBox("Hello, world!")
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The following desktop code displays a multiline Message box. The text after the two `EndOfLine</api/text/endofline>` functions appears in plain type and a smaller font size. Please note that it is entered as one line in the Code Editor.

``` xojo
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 desktop code displays a Message box with "Yes" and "No" buttons.

``` xojo
Var 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
```

## Compatibility

All project types on all supported operating systems.

## See also

`EndOfLine</api/text/endofline>`, `MessageDialog</api/user_interface/desktop/messagedialog>`, `MessageDialogButton</api/user_interface/desktop/messagedialogbutton>`, `WebDialog</api/user_interface/web/webdialog>`, `MobileMessageBox</api/user_interface/mobile/mobilemessagebox>` classes.
