📄 vbs571.htm
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML><HEAD><TITLE>Dim Statement</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="As,To,Dim statement,Public statement,Private statement,declaring arrays,arrays declaring,allocating storage,declaring variables,storage allocating,variables declaring,declaring dynamic arrays,dynamic arrays declaring,arrays,storage,variables,dynamic arrays"><META NAME="Description" CONTENT="Dim Statement"></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>Dim Statement</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="vbs572.htm">See Also</A></FONT>
<HR noshade SIZE=1>
<H5>Description</H5>
<BLOCKQUOTE>Declares variables and allocates storage space.</BLOCKQUOTE>
<H5>Syntax</H5>
<BLOCKQUOTE><b>Dim</b> <i>varname</i>[<b>(</b>[<i>subscripts</i>]<b>)</b>][<b>, </b><i>varname</i>[<b>(</b>[<i>subscripts</i>]<b>)</b>]] <b>. . .</b><P>
The <b>Dim</b> statement syntax has these parts:<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>varname</i></FONT></TD>
<TD><FONT SIZE=2>Name of the variable; follows standard <A HREF="vbs0.htm#defVariable">variable</A> naming conventions.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>subscripts</i></FONT></TD>
<TD><FONT SIZE=2>Dimensions of an
<A HREF="vbs0.htm#defArray">array</A> variable; up to 60 multiple dimensions may be declared. The <i>subscripts</i> argument uses the following syntax:
<P><i>upperbound </i>[<b>,</b><i>upperbound</i>] <b>. . .</b>
<P>The lower bound of an array is always zero.</FONT></TD></TR></TABLE></BLOCKQUOTE>
<H5>Remarks</H5>
<BLOCKQUOTE>Variables declared with <b>Dim</b> at the <A HREF="vbs0.htm#defScriptLevel">script level</A> are available to all procedures within the script. At the <A HREF="vbs0.htm#defProcLevel">procedure level</A>, variables are available only within the procedure. <P>
You can also use the <b>Dim</b> statement with empty parentheses to declare a dynamic array. After declaring a dynamic array, use the <b>ReDim</b> statement within a procedure to define the number of dimensions and elements in the array. If you try to redeclare a dimension for an array variable whose size was explicitly specified in a <b>Dim </b>statement, an error occurs.<P>
When variables are initialized, a numeric variable is initialized to 0 and a string is initialized to a zero-length string ("").
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=87%><TR><TD COLSPAN=2 VALIGN=BOTTOM><HR noshade size=1></TD></TR><TR>
<TD VALIGN=TOP><FONT SIZE=2><b>Tip</b> When you use the <b>Dim</b> statement in a procedure, you generally put the <b>Dim</b> statement at the beginning of the procedure.</FONT></TD></TR><TR><TD COLSPAN=2 VALIGN=TOP><HR noshade size=1></TD></TR></TABLE></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 + -