VBScript » Functions » MsgBox

Version: 1.0

Syntax:
MsgBox(Prompt, Buttons, Title)
Prompt
The Prompt argument is the message string that appears in the message box.
Buttons
The optional Buttons argument must only use the constant or value in the MsgBox CONSTANTS.
Title
The optional Title argument is the title that appears at the top of the message box window.

Note you may use either the Title argument or the HelpFile, Context arguments. You cannot use both at the same time.
HelpFile
The optional HelpFile argument is a string that specifies the help file that you wish to display. This must be either a .chm or .hlp file.

Note you may use either the Title argument or the HelpFile, Context arguments. You cannot use both at the same time.
Context
The optional Context argument specifies the help context number in the help file of the topic you wish to display. If you have created your own custom help file, then the Context argument is mandatory.

The MsgBox function creates a dialog box with a specified message and prompts the user to click a button, upon which the dialog box closes and a value relating to which button was clicked is returned. These values, along with their Constants, are listed in the table below.

MsgBox Return Values

CONSTANT VALUE BUTTON
VBOK 1 OK
VBCancel 2 Cancel
VBAbort 3 Abort
VBRetry 4 Retry
VBIgnore 5 Ignore
VBYes 6 Yes
VBNo 7 No


MsgBox Button Constants

CONSTANT VALUE DESCRIPTION
VBOKOnly 0 Show OK button
VBOKCancel 1 Show OK and cancel buttons
VBAbortRetryIgnore 2 Show abort, retry, ignore buttons
VBYesNoCancel 3 Show yes, no cancel buttons
VBYesNo 4 Show yes, no buttons
VBRetryCancel 5 Show retry, cancel buttons
VBCritical 16 Show critical message icon
VBQuestion 32 Show warning query button
VBExclamation 48 Show warning message icon
VBInformation 64 Show information message icon
VBDefaultButton1 0 First button is default
VBDefaultButton2 256 Second button is default
VBDefaultButton3 512 Third button is default
VBDefaultButton4 768 Fourth button is default
VBApplicationModal 0 Demands that the user respond to the dialog before allowing continuation of work in current application
VBSystemModal 4096 Causes suspension of all applications until the user responds to the dialog

Examples

Code:
< INPUT TYPE="BUTTON" NAME="button0" VALUE="Click Here!" >
< SCRIPT LANGUAGE="VBScript" >
Sub button0_onclick
MsgBox "Please Click OK"
End Sub
< /SCRIPT >
Explanation:

The default message box includes the OK button.

Language(s): VBScript
Code:
< INPUT TYPE="BUTTON" NAME="button_1" VALUE="Click Here!"> >
< SCRIPT LANGUAGE="VBScript" >
Sub button_1_onclick
MsgBox "Please Click OK", VBOKCancel
End Sub
< /SCRIPT >
Language(s): VBScript
Code:
< INPUT TYPE="BUTTON" NAME="button_2" VALUE="Click Here!"> >
< SCRIPT LANGUAGE="VBScript" >
Sub button_2_onclick
MsgBox "Please Click!", VBRetryCancel, "MsgBox Demo"
End Sub
< /SCRIPT >
Language(s): VBScript
Code:
MsgBox "Date is not valid", vbMsgBoxHelpButton, "help_folder/date_help_file.hlp", 71
Output:
Not demonstrated.
Language(s): VBScript
Code:
<INPUT TYPE="button" NAME="button0" VALUE="Click Here!"> OK
<INPUT TYPE="button" NAME="button1" VALUE="Click Here!"> OK, Cancel
<INPUT TYPE="button" NAME="button2" VALUE="Click Here!"> Abort, Retry, Ignore
<INPUT TYPE="button" NAME="button3" VALUE="Click Here!"> Yes, No, Cancel
<INPUT TYPE="button" NAME="button4" VALUE="Click Here!"> Yes, No
<INPUT TYPE="button" NAME="button5" VALUE="Click Here!"> Retry, Cancel
<INPUT TYPE="button" NAME="button16" VALUE="Click Here!"> Critical OK
<INPUT TYPE="button" NAME="button32" VALUE="Click Here!"> Warning Query OK
<INPUT TYPE="button" NAME="button48" VALUE="Click Here!"> Warning Message OK
<INPUT TYPE="button" NAME="button64" VALUE="Click Here!"> Info OK
<INPUT TYPE="button" NAME="button34" VALUE="Click Here!"> Warning Query, Abort, Retry, Cancel

<SCRIPT LANGUAGE="VBScript">
sub button0_onclick
msgbox "Hello", 0, "VBScript Demo 0"
end sub
sub button1_onclick
msgbox "Hello", 1, "VBScript Demo 1"
end sub
sub button2_onclick
msgbox "Hello", 2, "VBScript Demo 2"
end sub
sub button3_onclick
msgbox "Hello", 3, "VBScript Demo 3"
end sub
sub button4_onclick
msgbox "Hello", 4, "VBScript Demo 4"
end sub
sub button5_onclick
msgbox "Hello", 5, "VBScript Demo 5"
end sub
sub button16_onclick
msgbox "Hello", 16, "VBScript Demo 16"
end sub
sub button32_onclick
msgbox "Hello", 32, "VBScript Demo 32"
end sub
sub button48_onclick
msgbox "Hello", 48, "VBScript Demo 48"
end sub
sub button64_onclick
msgbox "Hello", 64, "VBScript Demo 64"
end sub
sub button34_onclick
msgbox "Hello", 2+32, "VBScript Demo 2+32"
end sub
</SCRIPT>
Language(s): VBScript

See Also: