Redim: Array Already Dimensioned Msg After Dim w/ Subscripts

Last reviewed: June 21, 1995
Article ID: Q83238
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 3.0
- Microsoft Visual Basic programming system for Windows, version 1.0

SUMMARY

You can use the ReDim statement to redimension a dynamic array only if the array has been previously dimensioned with empty parentheses (no subscripts), or if the array has been previously redimensioned with ReDim. If you specified subscripts to originally dimension the array in a Global or Dim statement, or if you previously dimensioned the array using the Static statement in a Sub or Function, redimensioning the array will cause an "Array already dimensioned" error.

MORE INFORMATION

You can use the ReDim statement to dimension an array that you have already declared with empty parentheses either in the Global module or in the general Declarations section. You can also use ReDim to redimension arrays that you have dimensioned with ReDim previously from any Sub or Function procedure.

Therefore, if you need to redimension an array in your program after using the array, first dimension the array in the Global module using the Global statement, or in the general Declarations section using Dim with no subscripts. Then use ReDim with the original dimensions. Later on, you can redimension this array again with different subscripts.

This will enable you to change the number of subscripts in each dimension of an array [for example, from x(15, 15) to x(32, 24)]. However, you cannot use ReDim to change the number of dimensions in an array. For example, you cannot redimension an array from two dimensions, such as x(15, 15), to three dimensions, such as x(64, 1, 5).


Additional reference words: 1.00 2.00 3.00
KBCategory: kbprg kbcode
KBSubcategory: PrgOptTips


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.