📄 vbs595.htm
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML>
<HEAD><TITLE>ReDim 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,ReDim statement,Preserve,resizing arrays,arrays resizing,declaring arrays,arrays declaring,allocating storage,declaring variables,reallocating arrays,storage allocating,arrays reallocating,variables declaring,reinitializing arrays,arrays reinitializing,declaring dynamic arrays,dynamic arrays declaring,arrays changing dimensions,arrays,storage,variables,dynamic arrays"><META NAME="Description" CONTENT="ReDim 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>ReDim 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="vbs596.htm">See Also</A></FONT>
<HR noshade SIZE=1>
<H5>Description</H5>
<BLOCKQUOTE>Used at
<A HREF="vbs0.htm#defProcLevel">procedure level</A> to declare
dynamic-array variables and allocate or reallocate storage space.</BLOCKQUOTE>
<H5>Syntax</H5>
<BLOCKQUOTE>
<b>ReDim</b> [<b>Preserve</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>ReDim</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><b>Preserve</b></FONT></TD>
<TD><FONT SIZE=2>Preserves the data in an existing <A HREF="vbs0.htm#defArray">array</A> when you change the size of the last dimension.</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 array variable; up to 60 multiple dimensions may be declared. The <i>subscripts</i> argument uses the following syntax:<P>
<i>upper </i>[<b>,</b><i>upper</i>] <b>. . .</b><p>
The lower bound of an array is always zero.</FONT></TD></TR>
</TABLE>
</BLOCKQUOTE>
<H5>Remarks</H5>
<BLOCKQUOTE>The <b>ReDim</b> statement is used to size or resize a dynamic array that has already been formally declared using a <b>Private</b>, <b>Public</b>, or <b>Dim</b> statement with empty parentheses (without dimension subscripts). You can use the <b>ReDim</b> statement repeatedly to change the number of elements and dimensions in an array.<P>
If you use the <b>Preserve</b> keyword, you can resize only the last array dimension, and you can't change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array. The following example shows how you can increase the size of the last dimension of a dynamic array without erasing any existing data contained in the array.<P>
<BLOCKQUOTE><PRE><FONT FACE="Courier New" SIZE=3><FONT COLOR="#FF0000">ReDim</FONT> X(10, 10, 10)
. . .
<FONT COLOR="#FF0000">ReDim Preserve</FONT> X(10, 10, 15)
</FONT></PRE>
</BLOCKQUOTE>
<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>Caution</b> If you make an array smaller than it was originally, data in the eliminated elements is lost.</FONT></TD></TR>
<TR><TD COLSPAN=2 VALIGN=TOP><hr noshade size=1></TD></TR></TABLE>
When variables are initialized, a numeric variable is initialized to 0 and a string variable is initialized to a zero-length string (""). A variable that refers to an object must be assigned an existing object using the <b>Set</b> statement before it can be used. Until it is assigned an object, the declared object variable has the special value
<A HREF="vbs0.htm#defNothing"><b>Nothing</b></A>.</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 + -