Search here for all the info you want in this Blog

Dynamic Arrays


VBScript supports dynamic arrays, whose size can change during runtime. Dynamic arrays can change
the number of dimensions and the size of any or all dimensions. These arrays are initially declared
using the Dim (or ReDim) keyword followed by a closed parenthesis. Then, prior to using the dynamic
array, the ReDim keyword is used to specify the number of dimensions and size of each dimension.
The ReDim can subsequently be used to modify the dynamic array’s number of dimensions or size of
each dimension. The Preserve keyword can be used to preserve the contents of the array as the
resizing takes place.

For example:
Dim MyArray(), x
ReDim MyArray(19) ‘ MyArray has 20 elements
MyArray(0) = 10 ‘ Assign values to first 2 elements
MyArray(1) = 20
ReDim Preserve MyArray(24) ‘ change MyArray to a 25 element array
x = MyArray(0) ‘ variable x is assigned value of 10

There is no limit to the number of times you can resize a dynamic array. However, if you make the array
smaller you will lose the data in the eliminated elements

No comments:

Post a Comment