Definitions

ReDim

ReDim

ReDim, short for re-dimension, is a Visual Basic 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)

References

Search another word or see ReDimon Dictionary | Thesaurus |Spanish
  • Please Login or Sign Up to use the Recent Searches feature
FAVORITES
RECENT