VBScript MsgBox Function

Definition and Usage

The MsgBox function can display a message box, wait for the user to click a button, and then return the value indicating which button was clicked.

The MsgBox function can return the following values:

  • 1 = vbOK - The OK button is clicked.
  • 2 = vbCancel - The cancel button is clicked.
  • 3 = vbAbort - The terminate button is clicked.
  • 4 = vbRetry - The retry button is clicked.
  • 5 = vbIgnore - The ignore button is clicked.
  • 6 = vbYes - The yes button is clicked.
  • 7 = vbNo - The no button is clicked.

Comment:When both the helpfile and context parameters are specified, the user can press the F1 key to view the help.

Tip:See the InputBox function.

Syntax

MsgBox(prompt[,buttons][,title][,helpfile,context])
Parameters Description
prompt Required. The string expression that is displayed in the dialog box as the message. The maximum length of prompt is approximately 1024 characters, depending on the width of the characters used. If there are multiple lines in prompt, the lines can be separated by carriage return (Chr(13)), line feed (Chr(10)), or a combination of both (Chr(13) & Chr(10)).
buttons

The value expression, which is the sum of the numerical values representing the number and type of buttons to be displayed, the icon style used, the identifier for the default button, and the style of the message box. If omitted, the default value for buttons is 0.

The value of button:

  • 0 = vbOKOnly - Only display the OK button.
  • 1 = vbOKCancel - Display the OK and cancel buttons.
  • 2 = vbAbortRetryIgnore - Display the abort, retry, and ignore buttons.
  • 3 = vbYesNoCancel - Display the yes, no, and cancel buttons.
  • 4 = vbYesNo - Display the yes and no buttons.
  • 5 = vbRetryCancel - Display the retry and cancel buttons.
  • 16 = vbCritical - Display the critical information icon.
  • 32 = vbQuestion - Display the warning query icon.
  • 48 = vbExclamation - Display the warning message icon.
  • 64 = vbInformation - Display the information message icon.
  • 0 = vbDefaultButton1 - The first button is the default button.
  • 256 = vbDefaultButton2 - The second button is the default button.
  • 512 = vbDefaultButton3 - The third button is the default button.
  • 768 = vbDefaultButton4 - The fourth button is the default button.
  • 0 = vbApplicationModal - The application mode: the user must respond to the message box to continue working in the current application.
  • 4096 = vbSystemModal - System Modal: All applications are suspended until the user responds to the message box.

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 of values (16, 32, 48, 64) is used to describe the style of the icons; the third group of values (0, 256, 512) determines the default button; and the fourth group of values (0, 4096) determines the style of the message box. When generating the buttons parameter value by adding these numbers, only one number can be taken from each group.

title A string expression that displays in the dialog box title bar. If title is omitted, the name of the application is displayed in the title bar.
helpfile A string expression that identifies the help file that provides context-related help for the dialog box. If helpfile is provided, context must also be provided. Not available on 16-bit system platforms.
context A numeric expression that identifies the context number assigned to a help topic by the author of the help file. If context is provided, helpfile must also be provided. Not available on 16-bit system platforms.

Example

dim answer
answer=MsgBox("Hello everyone!",65,"Example")
document.write(answer)