Func Msgbox
* * 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 clicked
* 2 = vbCancel β Cancel button clicked
* 3 = vbAbort β Abort button clicked
* 4 = vbRetry β Retry button clicked
* 5 = vbIgnore β Ignore button clicked
* 6 = vbYes β Yes button clicked
* 7 = vbNo β No button clicked
**Note:** When both the helpfile and context parameters are specified, the user can press F1 to view help.
**Tip:** See the InputBox function.
### Syntax
MsgBox(prompt[,buttons][,title][,helpfile,context])
| Parameter | Description |
| --- | --- |
| prompt | Required. A string expression displayed as a message in the dialog box. The maximum length of prompt is approximately 1024 characters, depending on the width of the characters used. If prompt contains multiple lines, you can separate them using carriage return (Chr(13)), line feed (Chr(10)), or a combination of both (Chr(13) & Chr(10)). |
| buttons | Optional. A numeric sum specifying the number and type of buttons to display, the icon style to use, the default button identifier, and the message box style. Default value is 0. * 0 = vbOKOnly β Displays only the OK button * 1 = vbOKCancel β Displays OK and Cancel buttons * 2 = vbAbortRetryIgnore β Displays Abort, Retry, and Ignore buttons * 3 = vbYesNoCancel β Displays Yes, No, and Cancel buttons * 4 = vbYesNo β Displays Yes and No buttons * 5 = vbRetryCancel β Displays Retry and Cancel buttons * 16 = vbCritical β Displays critical message icon * 32 = vbQuestion β Displays question mark icon * 48 = vbExclamation β Displays exclamation point icon * 64 = vbInformation β Displays information icon * 0 = vbDefaultButton1 β First button is the default button * 256 = vbDefaultButton2 β Second button is the default button * 512 = vbDefaultButton3 β Third button is the default button * 768 = vbDefaultButton4 β Fourth button is the default button * 0 = vbApplicationModal β Application modal (user must respond to the message box before continuing work in the current application) * 4096 = vbSystemModal β System modal (all applications are suspended until the user responds to the message box) The button values can be grouped into four categories: the first group (0β5) specifies the button types and count; the second group (16, 32, 48, 64) specifies the icon style; the third group (0, 256, 512, 768) determines the default button; and the fourth group (0, 4096) determines the message box style. When summing these numbers to produce the buttons parameter value, only one number may be selected from each group. |
| title | Optional. Title of the message box. Default is the application name. |
| helpfile | Optional. A string expression identifying the Help file that provides context-sensitive Help for the dialog box. Must be used together with the context parameter. |
| context | Optional. A numeric expression identifying the context ID assigned by the Help file author to a specific Help topic. Must be used together with the helpfile parameter. |
## Examples
## Example 1
MsgBox("Hello world")
[Try it yourself Β»](#)
## Example 2
Message box with line breaks:
MsgBox("Hello" & chr(13) & "world")
[Try it yourself Β»](#)
## Example 3
Different button sets and different icons. Returns the value of the clicked button:
x=MsgBox("Hello world",_n_)
document.getElementById("myDiv").innerHTML="You clicked: " & x
[Try it yourself Β»](#)
## Example 4
Message box with title:
x=MsgBox("Are you a programmer",4,"Please answer")
[Try it yourself Β»](#)
* * Complete VBScript Reference Manual](#)
YouTip