MsgBox (function)

Syntax MsgBox (msg [,[type] [,title]])
Description Displays a message in a dialog box with a set of predefined buttons, returning an Integer representing which button was selected.
Comments
Important: The message box has an approximate maximum allowed number of characters.
The:
  • Message box is limited to 3/5ths of the screen's horizontal resolution.
  • Actual message will be truncated if the message box exceeds this width.
It is estimated that on a 1280x800 resolution approximately 128 characters fit in the message box. The estimation is based on the fact that some letters/numbers/symbols require more than one character space (e.g. M); some less (e.g. i). Therefore the exact allowed number of characters depends on what numbers/letters/symbols are used in the message.
The MsgBox function takes the following parameters:
Parameter Description
msg Message to be displayed—any expression convertible to a String. End-of-lines can be used to separate lines (either a carriage return, line feed, or both). If a given line is too long, it will be word-wrapped. If msg contains character 0, then only the characters up to the character 0 will be displayed. The width and height of the dialog box are sized to hold the entire contents of msg. A runtime error is generated if msg is Null .
type Integer specifying the type of dialog box (see below).
title Caption of the dialog box. This parameter is any expression convertible to a String. If it is omitted, then the script is used. A runtime error is generated if title is Null .
The MsgBox function returns one of the following values:
Constant Value The following is clicked
ebOK 1 OK
ebCancel 2 Cancel
ebAbort 3 Abort
ebRetry 4 Retry
ebIgnore 5 Ignore
ebYes 6 Yes
ebNo 7 No
The type parameter is the sub of any of the following values:
Constant Value Displays
ebOKOnly 0 OK button
ebOKCancel 1 OK and Cancel buttons
ebAbortRetryIgnore 2 Abort, Retry and Ignore buttons
ebYesNoCancel 3 Displays Yes, No, and Cancel buttons.
ebYesNo 4 Yes and No buttons.
ebRetryCancel 5 Retry and Cancel buttons
ebCritical 16 Stop icon
ebQuestion 32 Question Mark icon
ebExclamation 48 Exclamation Point icon
ebInformation 64 Information icon
ebDefaultButton1 0 First button is the default button.
ebDefaultButton2 256 Second button is the default button.
ebDefaultButton3 512 Third button is the default button.
ebApplicationModal 0 Application modal; the current application is suspended until the dialog box is closed.
The default value for type is 0 (display only the OK button, making it the default). Breaking Text across Lines The msg parameter can contain end-of-line characters, forcing the text that follows to start on a new line. The following example shows how to display a string on two lines:
 MsgBox "This is on" + Chr(13) + Chr(10) + "two lines."
The carriage-return or line-feed characters can be used by themselves to designate an end-of-line.
r = MsgBox("Hello, World")
r = MsgBox("Hello, World",ebYesNoCancel Or ebDefaultButton1)
r = MsgBox("Hello, World",ebYesNoCancel Or ebDefaultButton1 Or ebCritical)
Example
Sub Main()
  MsgBox "This is a simple message box."
  MsgBox "This is a message box with a title and an icon.",_
    ebExclamation,"Simple"
  MsgBox "This message box has OK and Cancel buttons.",_
    ebOkCancel,"MsgBox"
  MsgBox "This message box has Abort, Retry, and Ignore buttons.",_
    ebAbortRetryIgnore,"MsgBox"
  MsgBox "This message box has Yes, No, and Cancel buttons.",_
    ebYesNoCancel Or ebDefaultButton2,"MsgBox"
  MsgBox "This message box has Yes and No buttons.",ebYesNo,"MsgBox"
  MsgBox "This message box has Retry and Cancel buttons.",_
    ebRetryCancel,"MsgBox"
  MsgBox "This message box is system modal!",ebSystemModal
End Sub
See Also AskBox$ (function); AskPassword$ (function); InputBox, InputBox$ (functions); OpenFilename$ (function); SaveFilename$ (function); SelectBox (function); AnswerBox (function).
Note MsgBox displays all text in its dialog box in 8-point MS Sans Serif.