Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

VBScript MsgBox Function

VBScript MsgBox Function


VBScript reference manual 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:

**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.
  • 0 = vbOKOnly - Display OK button only
  • 1 = vbOKCancel - Display OK and Cancel buttons
  • 2 = vbAbortRetryIgnore - Display Abort, Retry, and Ignore buttons
  • 3 = vbYesNoCancel - Display Yes, No, and Cancel buttons
  • 4 = vbYesNo - Display Yes and No buttons
  • 5 = vbRetryCancel - Display Retry and Cancel buttons
  • 16 = vbCritical - Display critical message icon
  • 32 = vbQuestion - Display warning query icon
  • 48 = vbExclamation - Display warning message icon
  • 64 = vbInformation - Display information message icon
  • 0 = vbDefaultButton1 - First button is the default
  • 256 = vbDefaultButton2 - Second button is the default
  • 512 = vbDefaultButton3 - Third button is the default
  • 768 = vbDefaultButton4 - Fourth button is the default
  • 0 = vbApplicationModal - Application modal (the 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)
  • 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 »


    VBScript reference manual Complete VBScript Reference Manual