|
ReDim | ||
ReDim ArrayName(ArraySize) | ||
Parameters: NONE | ||
Returns: NONE | ||
The ReDim command works virtually the same as the Dim command, with one key difference. ReDim allows the programmer to resize a previously declared array without destorying it's contents. This allows us to dynamically expand or shrink arrays as need be. However you should be aware that shrinking an array will discard any infromation outside of the new dimensions. So if that information is important to you, it will be lost. So some care is needed. FACTS: * ReDim can be used with any type of dynamic array, including Integer(),Float#(), String$() and even Typed Variables & Arrays (Types). * Array dimensions must be positive values. * Array Indexes are zero inclusive. That means 0,1,2, etc .. up to the Number of Elements are valid Indexes. Which is the traditional BASIC convention. * Arrays can be as large as you like, providing it's total size (in all dimensions) is smaller than (2^28), which is massive anyway. So you're really only limited by the amount of the memory your computer has. * You can not change the number of dimensions that the array previously had. Mini Tutorial: In this example were creating an Array with DIM, then resizing it using the REDIM command.
Since ReDim gives us easy control over an arrays size. We'll commonly use when we wish to dynamicly change the size of an array. In this example, we're creating the array table(), then randomly adding values to it, resizing it when need be.
|
||
Example Source: Download This Example
|
Related Info: | ArrayBasics | Dim | GetArrayElements | GetArrayStatus | UnDim : |
|
|||||||||||||||||||||||||||||||||||||||
(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com |