Declaring Array Variables
Arrays in a Basic Control Engine script are declared using any of the following statements:
Dim
Public
Private
For example:
Dim a(10) As Integer
Public LastNames(1 to 5,-2 to 7) As Variant
Private
Arrays of any data type can be created, including Integer, Long, Single, Double, Boolean, Date, Variant, Object, user-defined structures, and data objects.
The lower and upper bounds of each array dimension must be within the following range:
-32768 <= bound <= 32767
Arrays can have up to 60 dimensions.
Arrays can be declared as either fixed or dynamic, as described below.
|
Fixed Arrays
The dimensions of fixed arrays cannot be adjusted at execution time. Once declared, a fixed array will always require the same amount of storage. Fixed arrays can be declared with the Dim,Private, or Public statement by supplying explicit dimensions. The following example declares a fixed array of ten strings:
Dim a(10) As String
Fixed arrays can be used as members of user-defined data types. The following example shows a structure containing fixed-length arrays:
Type Foo
rect(4) As Integer
colors(10) As Integer
End Type
Only fixed arrays can appear within structures.
|
Dynamic Arrays
Dynamic arrays are declared without explicit dimensions, as shown below:
Public Ages() As Integer
Dynamic arrays can be resized at execution time using the Redim statement:
Redim Ages$(100)
Subsequent to their initial declaration, dynamic arrays can be redimensioned any number of times. When redimensioning an array, the old array is first erased unless you use the Preserve keyword, as shown below:
Redim Preserve Ages$(100)
Dynamic arrays cannot be members of user-defined data types.
|
Passing Arrays
Arrays are always passed by reference.
|
Querying Arrays
The following table describes the functions used to retrieve information about arrays.
|
Use this function
|
to
|
LBound
|
Retrieve the lower bound of an array. A runtime error is generated if the array has no dimensions.
|
UBound
|
Retrieve the upper bound of an array. A runtime error is generated if the array has no dimensions.
|
ArrayDims
|
Retrieve the number of dimensions of an array. This function returns 0 if the array has no dimensions
|