Arrays

An array is a collection of data values of the same type. The number of values in the array is called the dimension. The individual values are referred to by using the name of the array following by an integer expression enclosed in square brackets. This integer value is called a subscript and runs from zero to one less than the dimension.

For example, if ad is an array of three doubles, ad[0] refers to the first value, ad[1] to the second, and ad[2] to the third or last value. The following code sample calculates the average value of an array of 20 voltage readings:

adVolts: Double[20]

dAverage: Double

dSum: Double

n: Short

dSum = 0

for n=0 to 19

dSum=dSum+adVolts[n]

next

dAverage=dSum/20

If the subscript value is less than zero or greater or equal to the dimension of the array, then an error occurs. For constant literal subscripts this is checked when the code is parsed. For all other cases the check is made at run time.

Maximum Size of an Array

The size of the array is limited to 32 bit which is 2 GB (2147483647 bytes). Make sure you have enough memory before you define a very large array. Otherwise your computer will run out of memory and will slow down or even crash. Couple of MB would be no problem. The maximum dim size of an array is 16.

See Also

Arrays and Structs, Arrays and Variants, Arrays as Procedure Arguments, Assignment of Arrays, Multiple Dimensions of Arrays, Strings as Arrays, User Defined Data Types