📄 vbs164.htm
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML>
<HEAD><TITLE>MsgBox Function</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso8859-1">
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META NAME="PRODUCT" CONTENT="Visual Basic Scripting Edition">
<META NAME="TECHNOLOGY" CONTENT="SCRIPTING">
<META NAME="CATEGORY" CONTENT="Language Reference">
<META NAME="Keywords" CONTENT="MsgBox function,message box,modal forms,system modal,alert visual,warning visual,application modal,displaying prompts,displaying messages,prompts displaying,buttons user choice,messages displaying,creating dialog boxes,dialog boxes creating,alert,warning,prompts,buttons,messages,dialog boxes">
<META NAME="Description" CONTENT="MsgBox Function"></HEAD>
<BODY BGCOLOR=FFFFFF LINK=#0033CC>
<!--TOOLBAR_START-->
<!--TOOLBAR_EXEMPT-->
<!--TOOLBAR_END-->
<FONT FACE="Verdana, Arial, Helvetica" SIZE=2>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR VALIGN=TOP><TD WIDTH=360>
<FONT SIZE=1 COLOR=#660033>Microsoft® Visual Basic® Scripting Edition</FONT><BR>
<FONT SIZE=5 COLOR=#660033><B>MsgBox Function</B></FONT>
</TD>
<TD ALIGN=RIGHT>
<FONT SIZE=2> <A HREF="vbstoc.htm">Language Reference</A> <BR>
<A HREF="vbs16.htm">Version 1</A> <P></FONT>
</TD></TR>
</TABLE>
<FONT SIZE=2><P>
<A HREF="vbs165.htm">See Also</A></FONT>
<HR noshade SIZE=1>
<H5>Description</H5>
<BLOCKQUOTE>Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.</BLOCKQUOTE>
<H5>Syntax</H5>
<BLOCKQUOTE><b>MsgBox(</b><i>prompt</i>[<b>, </b><i>buttons</i>][<b>, </b><i>title</i>][<b>, </b><i>helpfile</i><b>, </b><i>context</i>]<b>)</b><P>
The <b>MsgBox</b> function syntax has these arguments:<P>
<TABLE WIDTH=87% BORDER=1 CELLPADDING=5 CELLSPACING=0>
<TR VALIGN=TOP BGCOLOR="#DDDDDD">
<TD><FONT SIZE=2><b>Part</b></FONT></TD>
<TD><FONT SIZE=2><b>Description</b></FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>prompt</i></FONT></TD>
<TD><FONT SIZE=2><A HREF="vbs0.htm#defStringExpression">String expression</A> displayed as the message in the dialog box. The maximum length of <i>prompt</i> is approximately 1024 characters, depending on the width of the characters used. If <i>prompt</i> consists of more than one line, you can separate the lines using a carriage return character (<b>Chr(</b>13<b>)</b>), a linefeed character (<b>Chr(</b>10<b>)</b>), or carriage return–linefeed character combination (<b>Chr(</b>13<b>) & Chr(</b>10<b>)</b>) between each line.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>buttons</i></FONT></TD>
<TD><FONT SIZE=2><A HREF="vbs0.htm#defNumericExpression">Numeric expression</A> 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. See Settings section for values. If omitted, the default value for <i>buttons</i> is 0.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>title</i></FONT></TD>
<TD><FONT SIZE=2>String expression displayed in the title bar of the dialog box. If you omit <i>title</i>, the application name is placed in the title bar.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>helpfile</i></FONT></TD>
<TD><FONT SIZE=2>String expression that identifies the Help file to use to provide context-sensitive Help for the dialog box. If <i>helpfile</i> is provided, <i>context</i> must also be provided. Not available on 16-bit platforms.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>context</i></FONT></TD>
<TD><FONT SIZE=2>Numeric expression that identifies the Help context number assigned by the Help author to the appropriate Help topic. If <i>context</i> is provided, <i>helpfile</i> must also be provided. Not available on 16-bit platforms.</FONT></TD></TR></TABLE></BLOCKQUOTE>
<H5>Settings</H5>
<BLOCKQUOTE>The <i>buttons</i> argument settings are:<P>
<TABLE WIDTH=87% BORDER=1 CELLPADDING=5 CELLSPACING=0>
<TR VALIGN=TOP BGCOLOR="#DDDDDD">
<TD><FONT SIZE=2><b>Constant</b></FONT></TD>
<TD><FONT SIZE=2><b>Value</b></FONT></TD>
<TD><FONT SIZE=2><b>Description</b></FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbOKOnly</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2> 0</FONT></TD>
<TD><FONT SIZE=2>Display <B>OK</B> button only.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbOKCancel</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2> 1</FONT></TD>
<TD><FONT SIZE=2>Display <B>OK</B> and <B>Cancel</B> buttons.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbAbortRetryIgnore</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2> 2</FONT></TD>
<TD><FONT SIZE=2>Display <B>Abort</B>, <B>Retry</B>, and <B>Ignore</B> buttons.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbYesNoCancel</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2> 3</FONT></TD>
<TD><FONT SIZE=2>Display <B>Yes</B>, <B>No</B>, and <B>Cancel</B> buttons.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbYesNo</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2> 4</FONT></TD>
<TD><FONT SIZE=2>Display <B>Yes</B> and <B>No</B> buttons.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbRetryCancel</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2> 5</FONT></TD>
<TD><FONT SIZE=2>Display <B>Retry</B> and <B>Cancel</B> buttons.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbCritical</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2> 16</FONT></TD>
<TD><FONT SIZE=2>Display <B>Critical Message</B> icon. </FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbQuestion</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2> 32</FONT></TD>
<TD><FONT SIZE=2>Display <B>Warning Query </B>icon.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbExclamation</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2> 48</FONT></TD>
<TD><FONT SIZE=2>Display <B>Warning Message</B> icon.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbInformation</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2> 64</FONT></TD>
<TD><FONT SIZE=2>Display <B>Information Message</B> icon.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbDefaultButton1</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2> 0</FONT></TD>
<TD><FONT SIZE=2>First button is default.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbDefaultButton2</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2> 256</FONT></TD>
<TD><FONT SIZE=2>Second button is default.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbDefaultButton3</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2> 512</FONT></TD>
<TD><FONT SIZE=2>Third button is default.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbDefaultButton4</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2> 768</FONT></TD>
<TD><FONT SIZE=2>Fourth button is default.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbApplicationModal</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2> 0</FONT></TD>
<TD><FONT SIZE=2>Application modal; the user must respond to the message box before continuing work in the current application.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><b>vbSystemModal</b></FONT></TD>
<TD ALIGN=CENTER><FONT SIZE=2>4096</FONT></TD>
<TD><FONT SIZE=2>System modal; all applications are suspended until the user responds to the message box.</FONT></TD></TR>
</TABLE>
<P>
The first group of values (0–5) describes the number and type 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 which button is the default; and the fourth group (0, 4096) determines the modality of the message box. When adding numbers to create a final value for the argument <i>buttons</i>, use only one number from each group.
</BLOCKQUOTE>
<H5>Return Values</H5>
<BLOCKQUOTE>The <B>MsgBox</B> function has the following return values:<P>
<TABLE WIDTH=87% BORDER=1 CELLPADDING=5 CELLSPACING=0>
<TR VALIGN=TOP BGCOLOR="#DDDDDD">
<TD WIDTH=15%><FONT SIZE=2><b>Constant</b></FONT></TD>
<TD WIDTH=5% ALIGN=CENTER><FONT SIZE=2><b>Value</b></FONT></TD>
<TD><FONT SIZE=2><b>Button</b></FONT></TD></TR>
<TR VALIGN=TOP>
<TD WIDTH=15%><FONT SIZE=2><b>vbOK</b></FONT></TD>
<TD WIDTH=5% ALIGN=CENTER><FONT SIZE=2>1</FONT></TD>
<TD><FONT SIZE=2><B>OK</B></FONT></TD></TR>
<TR VALIGN=TOP>
<TD WIDTH=15%><FONT SIZE=2><b>vbCancel</b></FONT></TD>
<TD WIDTH=5% ALIGN=CENTER><FONT SIZE=2>2</FONT></TD>
<TD><FONT SIZE=2><B>Cancel</B></FONT></TD></TR>
<TR VALIGN=TOP>
<TD WIDTH=15%><FONT SIZE=2><b>vbAbort</b></FONT></TD>
<TD WIDTH=5% ALIGN=CENTER><FONT SIZE=2>3</FONT></TD>
<TD><FONT SIZE=2><B>Abort</B></FONT></TD></TR>
<TR VALIGN=TOP>
<TD WIDTH=15%><FONT SIZE=2><b>vbRetry</b></FONT></TD>
<TD WIDTH=5% ALIGN=CENTER><FONT SIZE=2>4</FONT></TD>
<TD><FONT SIZE=2><B>Retry</B></FONT></TD></TR>
<TR VALIGN=TOP>
<TD WIDTH=15%><FONT SIZE=2><b>vbIgnore</b></FONT></TD>
<TD WIDTH=5% ALIGN=CENTER><FONT SIZE=2>5</FONT></TD>
<TD><FONT SIZE=2><B>Ignore</B></FONT></TD></TR>
<TR VALIGN=TOP>
<TD WIDTH=15%><FONT SIZE=2><b>vbYes</b></FONT></TD>
<TD WIDTH=5% ALIGN=CENTER><FONT SIZE=2>6</FONT></TD>
<TD><FONT SIZE=2><B>Yes</B></FONT></TD></TR>
<TR VALIGN=TOP>
<TD WIDTH=15%><FONT SIZE=2><b>vbNo</b></FONT></TD>
<TD WIDTH=5% ALIGN=CENTER><FONT SIZE=2>7</FONT></TD>
<TD><FONT SIZE=2><B>No</B></FONT></TD></TR>
</TABLE></BLOCKQUOTE>
<H5>Remarks</H5>
<BLOCKQUOTE>When both <i>helpfile</i> and <i>context</i> are provided, the user can press <B>F1</B> to view the Help topic corresponding to the context.<P>
If the dialog box displays a <B>Cancel</B> button, pressing the <B>ESC</B> key has the same effect as clicking <B>Cancel</B>. If the dialog box contains a <B>Help</B> button, context-sensitive Help is provided for the dialog box. However, no value is returned until one of the other buttons is clicked.
</BLOCKQUOTE>
<hr noshade size=1>
<p align=center><em><a href="../../common/colegal.htm">© 1997 by Microsoft Corporation. All rights reserved.</a></em></p>
</FONT></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -