Method
MsgBox
Warning
This item was deprecated in version 2019r2. Please use MessageBox or MessageDialog as a replacement.
Description
Displays message box showing the string passed. With the exception of simple message boxes, you should use the 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. The message is output to the console/terminal.
Desktop Apps
result = MsgBox(message [,buttons][,title])
Part |
Type |
Description |
---|---|---|
result |
Indicates which button was pressed. |
|
message |
Any valid string expression. |
|
buttons |
Optional code indicating the icon and choice of buttons displayed in the Message box. |
|
title |
Optional text displayed in the Title bar (Windows and Linux). |
Notes
Warning
MsgBox remains for Visual Basic (VB) compatibility-only. Instead use MessageBox.
Warning
You should avoid using MsgBox for displaying debugging messages. The displaying of the Message Box will alter event order and may give unexpected results. Instead use the Debugger, System.DebugLog or your own logging mechanism.
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 Xojo.
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.
Closing a MsgBox 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 for details.
The MsgBox buttons are not localized — this is a known bug (feedback report 4665).
Sample code
This code displays a one line Message box.
MsgBox("Hello, world!")
The following desktop code displays a multiline Message box. The text after the two EndOfLine functions appears in plain type and a smaller font size. 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 desktop code displays a Message box with "Yes" and "No" buttons.
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, MessageDialog, MessageDialogButton, WebDialog, MobileMessageBox classes.