|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
Array Size Declaration for Visual Basic 6.0 Users
Visual Basic 2005 updates array size declaration for interoperability with the common language runtime.
Visual Basic 6.0
In Visual Basic 6.0, you can specify the size of an array in its declaration, as in the following example:
Dim Month(0 To 11) As Integer
This causes the array to have a fixed size, which you cannot change with the ReDim statement.
Visual Basic 2005
In Visual Basic 2005, an array does not have a permanent size. The preceding example can be rewritten as either of the following declarations:
These declarations are equivalent. Each specifies an initial size, which you can change during execution with the ReDim statement. To initialize the elements, you can use the following syntax:
If you specify –1 for one of the dimensions, the array does not contain any elements. A ReDim statement can change an array back and forth between empty and nonempty.
Number of Dimensions
Although an array's size can change in Visual Basic 2005, the number of dimensions must be fixed. The following example declares a three-dimensional array:
The ReDim statement can set or change the size of each dimension, but the array always remains three-dimensional.