ReDim

From Seo Wiki - Search Engine Optimization and Programming Languages
Jump to navigationJump to search

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.[1]

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

If you like SEOmastering Site, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...