Arrays

    

Cypress Enable supports single and multi dimensional arrays.  Using arrays you can refer to a series of variables by the same name each with a separate index. Arrays have upper and lower bounds.  Enable allocates space for each index number in the array.  Arrays should not be declared larger then necessary.

 

All the elements in an array have the same data type. Enable supports arrays of  bytes, Booleans, longs, integers, singles, double, strings, variants and User Defined Types.

 

Ways to declare a fixed-size array:

 

      Global array, use the Dim statement outside the procedure section of a code module to declare the array.

 

      To create a local array, use the Dim statement inside a procedure.

 

 

Cypress Enable supports  Dynamic arrays.

 

Declaring an array. The array name must be followed by the upper bound in parentheses.  The upper bound must be an integer.

 

Dim  ArrayName (10) As Interger

Dim Sum (20) As Double

  

To create a global array, you simply use Dim outside the procedure:

 

Dim Counters (12) As Integer

Dim Sums (26) As Double

 

Sub Main () …

 

The same declarations within a procedure use Static or Dim:

 

Static Counters (12)  As Integer

Static Sums (22) As Double

 

The first declaration creates an array with 11 elements, with index numbers running from 0 to 10.  The second creates an array with 21 elements. To change the default lower bound to 1 place an Option Base statement in the Declarations section of a module:

 

Option Base 1

 

Another way to specify the lower bound is to provide it explicitly (as an integer, in the range -32,768 to 32,767) using the To key word:

 

Dim Counters (1 To 13) As Integer

Dim Sums (100 To 126) As String

 

In the preceding declarations, the index numbers of Counters run from 1 to 13, and the index numbers of Sums run from 100 to 126.

 

Note:  Many other versions of Basic allow you to use an array without first declaring it. Enable Basic does not allow this; you must declare an array before using it.

 

Loops often provide an efficient way to manipulate arrays.  For example, the following For loop initializes all elements in the array to 5:

 

Static Counters (1 To 20) As Integer

Dim I As Integer

   For I = 1 To 20

      Counter ( I ) = 5

   Next I

 

MultiDimensional Arrays

 

Cypress Enable supports multidimensional arrays.  For example the following example declares a two-dimensional array within a procedure.

 

Static Mat(20, 20) As Double

 

Either or both dimensions can be declared with explicit lower bounds.

 

Static Mat(1 to 10, 1 to 10) As Double

 

You can efficiently process a multidimensional array with the use of for loops.  In the following statements the elemtents in a multidimensional array are set to a value.

 

Dim L As Integer, J As Integer

   Static TestArray(1 To 10, 1 to 10) As Double

   For L = 1 to 10

   For J = 1 to 10

      TestArray(L,J) = I * 10 + J

   Next J

   Next L

 

Arrays can be more than two dimensional.  Enable does not have an arbitrary upper bound on array dimensions.

 

Dim ArrTest(5, 3, 2)

 

This declaration creates an arrray that has three dimensions with sizes 6 by 4, by 3  unless Option Base 1 is set previously in the code.  The use of Option Base 1 sets the lower bound of all arrays to 1 instead of 0.