VBScript MsgBox Function
MsgBox function displays a message box and wait for the user clicks a button, and returns a value indicating the button is clicked.
MsgBox function returns the following values:
- 1 = vbOK - OK button is clicked
- 2 = vbCancel - Cancel button is clicked
- 3 = vbAbort - Abort button is clicked
- 4 = vbRetry - Retry button is clicked
- 5 = vbIgnore - Ignore button is clicked
- 6 = vbYes - Yes button is clicked
- 7 = vbNo - No button is clicked
Note: When the helpfile and context parameters are specified, users press the F1 key to view the help.
Tip: See the InputBox function.
grammar
MsgBox(prompt[,buttons][,title][,helpfile,context])
参数 | 描述 |
---|---|
prompt | 必需。作为消息显示在对话框中的字符串表达式。prompt 的最大长度大约是 1024 个字符,这取决于所使用的字符的宽度。如果 prompt 中包含多个行,则可在各行之间用回车符(Chr(13))、换行符(Chr(10))或回车换行符的组合(Chr(13) & Chr(10))分隔各行。 |
buttons | 可选,是表示指定显示按钮的数目和类型、使用的图标样式,默认按钮的标识以及消息框样式的数值的总和。默认值为 0。
我们可以把按钮分成四组:第一组值(0-5)用于描述对话框中显示的按钮类型与数目;第二组值(16,32,48,64)用于描述图标的样式;第三组值(0,256,512,768)用于确定默认按钮;而第四组值(0,4096)则决定消息框的样式。在将这些数字相加以生成 buttons 参数值时,只能从每组值中取用一个数字。 |
title | 可选。消息框的标题。默认是应用程序的名称。 |
helpfile | 可选。字符串表达式,用于标识为对话框提供上下文相关帮助的帮助文件。必须与 context 参数一起使用。 |
context | 可选。数值表达式,用于标识由帮助文件的作者指定给某个帮助主题的上下文编号。必须与 helpfile 参数一起使用。 |
Examples
Example 2
Message box with line breaks:
<script type="text/vbscript">
MsgBox("Hello" & chr(13) & "world")
</script>
MsgBox("Hello" & chr(13) & "world")
</script>
try it"
Example 3
Different buttonsets and different icons. Click on the return value of the button:
<script type="text/vbscript">
x=MsgBox("Hello world",n)
document.getElementById("myDiv").innerHTML="You clicked: " & x
</script>
x=MsgBox("Hello world",n)
document.getElementById("myDiv").innerHTML="You clicked: " & x
</script>
try it"
Example 4
Message box with the title:
<script type="text/vbscript">
x=MsgBox("Are you a programmer",4,"Please answer")
</script>
x=MsgBox("Are you a programmer",4,"Please answer")
</script>
try it"
Complete VBScript Reference