Easy Tutorial
❮ Vbscript Summary Func Eval ❯

VBScript MsgBox Function



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 the InputBox function.

Syntax

Parameter Description
prompt Required. A string expression displayed as the message in the dialog box. The maximum length of prompt is approximately 1024 characters, depending on the width of the characters used. If prompt includes more than one line, you can separate the lines using a carriage return character (Chr(13)), a linefeed character (Chr(10)), or a carriage return/linefeed combination (Chr(13) & Chr(10)) between each line.
buttons Optional. A numeric expression 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 modality of the message box. The default value is 0. 0 = vbOKOnly - Displays OK button<br> 1 = vbOKCancel - Displays OK and Cancel buttons<br> 2 = vbAbortRetryIgnore - Displays Abort, Retry, and Ignore buttons<br> 3 = vbYesNoCancel - Displays Yes, No, and Cancel buttons<br> 4 = vbYesNo - Displays Yes and No buttons<br> 5 = vbRetryCancel - Displays Retry and Cancel buttons<br> 16 = vbCritical - Displays Critical Message icon<br> 32 = vbQuestion - Displays Warning Query icon<br> 48 = vbExclamation - Displays Warning Message icon<br> 64 = vbInformation - Displays Information Message icon<br> 0 = vbDefaultButton1 - The first button is the default<br> 256 = vbDefaultButton2 - The second button is the default<br> 512 = vbDefaultButton3 - The third button is the default<br> 768 = vbDefaultButton4 - The fourth button is the default<br> 0 = vbApplicationModal - Application modal (the user must respond to the message box before continuing work in the current application)<br> 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 (0-5) describes the type and number of buttons displayed in the dialog box; the second group (16, 32, 48, 64) describes the icon style; the third group (0, 256, 512, 768) determines the default button; and the fourth group (0, 4096) decides the modality of the message box. When adding these numbers to produce 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 used to provide context-sensitive help for the dialog box. Must be used with the context parameter.
context Optional. A numeric expression that identifies the context number assigned to the appropriate help topic by the help file author. Must be used with the helpfile parameter.

Example

Example 1

Example 2

Message box with line breaks:

Example 3

Different buttonsets and different icons. Returns the value of the clicked button:

Example 4

Message box with a title:


❮ Vbscript Summary Func Eval ❯