Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

VBScript MsgBox function


May 13, 2021 VBScript


Table of contents


VBScript MsgBox function

The function of the MsgBox function is to pop up a dialog box waiting for the user to click the button and return an Integer value indicating which button the user clicked.


VBScript MsgBox function Complete VBScript reference manual

The MsgBox function displays a message box that waits for the user to click a button and then returns the value indicating the button being clicked.

The MsgBox function returns the following value:

  • 1 - vbOK - OK button is clicked
  • 2 - vbCancel - Cancel button is clicked
  • 3 s vbAbort - Abort button is clicked
  • 4 - vbRetry - Retry button is clicked
  • 5 - vbIgnore - Ignore button is clicked
  • 6 s vbYes - Yes button is clicked
  • 7 - vbNo - No button is clicked

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

Tip: See InputBox functions.

Grammar

MsgBox(prompt[,buttons][,title][,helpfile,context])

parameter describe
prompt Required.The string expression in the dialog box is displayed as a message.The maximum length of PROMPT is approximately 1024 characters, depending on the width of the characters used.If you contain multiple rows in the PROMPT, you can use a return between the rows (CHR (13)), a wrap (CHR (10)) or the carriage return (CHR (13) & chr (10)) Separate each line.
buttons Optionally, it is the sum of the number of icon styles, default buttons, and numerical values of the message box style, using the icon style, the identity of the default button, and the value of the message frame style.The default is 0.
  • 0 = vbokonly - only the OK button is displayed
  • 1 = VBOKCANCEL - Show OK and Cancel Button
  • 2 = VBABORTRETRYIGNORE - Display Abort, Retry and Ignore buttons
  • 3 = Vbyesnocancel - Show Yes, NO and Cancel Button
  • 4 = Vbyesno - Display Yes and NO Button
  • 5 = VbretryCancel - Show Retry and Cancel Button
  • 16 = vbcritical - Show critical information icons
  • 32 = vbquestion - Show warning query icon
  • 48 = vbexclamation - Show Warning Message Icon
  • 64 = vbinformation - Display 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 - Fourth button for the default button
  • 0 = VBApplicationModal - Application mode (the user must respond to the message box to continue working in the current application)
  • 4096 = VBSYSTEMMODAL - System mode (all applications are suspended before users responding to message box)

We can divide the button into four groups: the first set value (0-5) is used to describe the type and number of buttons displayed in the dialog; the second set value (16, 32, 48, 64) is used to describe the style of the icon;The third group value (0, 256, 512, 768) is used to determine the default button; and the fourth set value (0, 4096) determines the style of the message box.When these numbers generate the Buttons parameter value, only one number can be taken from each group value.

title Optional.The title of the message box.By default is the name of the application.
helpfile Optional.String expressions, used to identify the help file for context-related help.It must be used with the context parameter.
context Optional.Numerical expressions, used to identify the context number assigned to a help topic by the author of the help file.It must be used with the HelpFile parameters.

Instance 1

<script type="text/vbscript">

MsgBox("Hello world")

</script>

Try it out . . .

Instance 2

Message box with line break:

<script type="text/vbscript">

MsgBox("Hello" & chr(13) & "world")

</script>

Try it out . . .

Instance 3

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

<script type="text/vbscript">

x=MsgBox("Hello world", n )
document.getElementById("myDiv").innerHTML="You clicked: " & x

</script>

Try it out . . .

Instance 4

Message box with title:

<script type="text/vbscript">

x=MsgBox("Are you a programmer",4,"Please answer")

</script>

Try it out . . .


VBScript MsgBox function Complete VBScript reference manual