Array whose size can be changed at runtime is called dynamic array.
The dynamic array is also sometimes called as redimmable array.
This type of array is used to store a list of values which can shrink or extend during execution of program.
Thus dynamic arrays are more flexible than the static/fixed size arrays.
Unlike the fixed size array, the size of the dynamic array is not specified at the time of declaration as:
Dim dynamicArray() as integer
Where 'dynamicArray' is name of a dynamic array of integer type.
The size of dynamic array is set by using a keyword 'Redim'.
The memory is allocated for array when the Redim is encountered (because the above declaration does not allocate memory space for the dynamic array).
The Redim is used as:
Redim dynamicArray(5)
This statement allocates the memory for 6 array elements (if lower bound is 0). Otherwise we can specify both the upper bound and lower bound of array by using Redim as:
Redim dynamicArray(1 to 5)
The size of dynamic array can be changed many times by using Redim, but each time Redim is encountered the previous values in that array are lost.
But there is also a way to preserve these previous values.
We can also change the upper and lower bounds of array by Redim.
The dynamic array is also sometimes called as redimmable array.
This type of array is used to store a list of values which can shrink or extend during execution of program.
Thus dynamic arrays are more flexible than the static/fixed size arrays.
Unlike the fixed size array, the size of the dynamic array is not specified at the time of declaration as:
Dim dynamicArray() as integer
Where 'dynamicArray' is name of a dynamic array of integer type.
The size of dynamic array is set by using a keyword 'Redim'.
The memory is allocated for array when the Redim is encountered (because the above declaration does not allocate memory space for the dynamic array).
The Redim is used as:
Redim dynamicArray(5)
This statement allocates the memory for 6 array elements (if lower bound is 0). Otherwise we can specify both the upper bound and lower bound of array by using Redim as:
Redim dynamicArray(1 to 5)
The size of dynamic array can be changed many times by using Redim, but each time Redim is encountered the previous values in that array are lost.
But there is also a way to preserve these previous values.
We can also change the upper and lower bounds of array by Redim.