VBScript MsgBoxFunction
Complete VBScript Reference
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 the F1 key to view help.
Tip:See the InputBox function.
Syntax
| Parameters | 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 the lines using carriage return characters (Chr(13)), linefeed characters (Chr(10)), or a combination of carriage return and linefeed characters (Chr(13) & Chr(10)). |
| buttons | Optional. A numeric value that is the sum of 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 separate the buttons into four groups: the first group of values (0-5) is used to describe the type and number of buttons displayed in the dialog box; the second group (16,32,48,64) is used to describe the icon style; the third group (0,256,512,768) is used to determine the default button; and the fourth group (0,4096) determines the style of the message box. When adding these numbers together to generate the buttons parameter value, you can only use one number from each group. |
| title | Optional. The title of the message box. The default is the application name. |
| helpfile | Optional. A string expression that identifies the help file used to provide 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 help file author. Must be used together with the helpfile parameter. |
Examples
Example 2
Message box with line breaks:
MsgBox("Hello" & chr(13) & "world")
</script>
Try it Yourself »
Example 3
Different buttonsets and different icons. Return the value of the clicked button:
x=MsgBox("Hello world",n)
document.getElementById("myDiv").innerHTML="You clicked: " & x
</script>
Try it Yourself »
Example 4
Message box with a title:
x=MsgBox("Are you a programmer",4,"Please answer")
</script>
Try it Yourself »
Complete VBScript Reference Other extensions