VBScript MsgBox Function
Complete VBScript Reference Manual
The MsgBox function displays a message box, waits for the user to click a button, and then returns a value indicating which button was clicked.
The MsgBox function returns the following values:
- 1 = vbOK - OK button was clicked
- 2 = vbCancel - Cancel button was clicked
- 3 = vbAbort - Abort button was clicked
- 4 = vbRetry - Retry button was clicked
- 5 = vbIgnore - Ignore button was clicked
- 6 = vbYes - Yes button was clicked
- 7 = vbNo - No button was clicked
**Note:** When both the helpfile and context parameters are specified, the user can press the F1 key to view help.
**Tip:** See also the InputBox function.
Syntax
MsgBox(prompt[,buttons][,title][,helpfile,context])
| Parameters | Description |
|---|---|
| prompt | Required. A string expression displayed as the message in the dialog box. The maximum length of prompt is about 1024 characters, depending on the width of the characters used. If prompt contains multiple lines, you can separate the lines with a carriage return (Chr(13)), a linefeed (Chr(10)), or a combination of carriage return and linefeed (Chr(13) & Chr(10)). |
| buttons | Optional. The sum of numeric values specifying the number and type of buttons to display, the icon style to use, the identity of the default button, and the style of the message box. The default value is 0.
|
We can divide the buttons into four groups: the first group of values (0-5) describes the type and number of buttons displayed in the dialog box; the second group of values (16,32,48,64) describes the icon style; the third group of values (0,256,512,768) determines the default button; and the fourth group of values (0,4096) determines the style of the message box. When adding these numbers together to generate the buttons parameter value, you can use only one number from each group.
| | title | Optional. The title of the message box. The default is the name of the application. | | helpfile | Optional. A string expression that identifies the help file providing context-sensitive help for the dialog box. Must be used together with the context parameter. | | context | Optional. A numeric expression that identifies the context number assigned to a help topic by the author of the help file. Must be used together with the helpfile parameter. |Example
Example 1
Try it »
Example 2
A message box with a line break:
Try it »
Example 3
Different buttonsets and different icons. Returns the value of the clicked button:
Try it »
Example 4
A message box with a title:
Try it »
Complete VBScript Reference Manual