Redim
Encyclopedia
ReDim, short for re-dimension, is a Visual Basic
Visual Basic
Visual Basic is the third-generation event-driven programming language and integrated development environment from Microsoft for its COM programming model...

 function that is used to resize arrays. By using this function you can add or remove space from an array. This function can only be used on arrays that are declared without dimensions.

For example, in the following declaration
Declaration with dimensions Declaration without dimensions
Dim MyArray(2) Dim MyArray
The array "MyArray" has been declared with dimensions, so ReDim cannot be used later to resize it. The array has been declared without dimensions (i.e. nothing in parentheses) thus ReDim can be used to resize the array.


The Preserve keyword is used to keep the data in an array intact. The syntax is as follows:
ReDim MyArray(3)

ReDim Preserve MyArray(3)


For arrays of multiple dimensions, you can only ReDim the latest dimension after the array has been redimensioned once, and your initial declaration must match the number of dimensions you want to use.

This works:

Dim MyArray

ReDim MyArray(1, 3)

ReDim MyArray(1, 4)


This does not work:

Dim MyArray

ReDim MyArray(1, 3)



This does not work:

Dim MyArray

ReDim MyArray(1, 3)

ReDim MyArray(2, 3)
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK