Campbell Scientific CR9000X Measurement and Control System User Manual

Page 175

Advertising
background image

Section 5. Program Declarations

Variables declared using the Dim statement cannot be viewed using the
datalogger's keyboard display or in a software package's numeric monitor. To
make variables available for display, use the Public declaration.

A Dim statement can be used for each variable declared, or multiple variables
can be defined on one line with one Dim statement. If the latter is done, the
variables should be separated by a comma (e.g., "Dim Scratch1, Scratch2,
Test" declares three variables). A variable array is created by following the
variable name with the number of elements enclosed in parenthesis (e.g., Dim
Temp(3) creates Temp(1), Temp(2), and Temp(3)). Two- and three-
dimensional arrays can also be defined. A declaration of Dim Temp(3,3,3)
would create 27 variables: Temp(1,1,1), Temp(1,1,2), Temp(1,1,3),
Temp(1,2,1), Temp(1,2,2) … Temp(3,3,3). In the program, the array can be
referenced using the multi-dimensional form, or using an index into the array.

Variables declared by Dim within a subroutine or function are local to that
subroutine or function. The same variable name can be used within other
subroutines or functions or as a global variable without conflict.

THE DIM STATEMENT HAS THESE PARTS:

VarName This parameter is the name for the defined variable. Variables names can be up

to 16 characters in length. Note, however, when outputting the variable to a
data table, the suffix containing the output type (e.g., _avg) is appended to the
end of the variable name. Therefore, to stay within the 16 character limit, most
variables should be no more than 12 characters (which allows for the 4
additional characters that may be needed for output processing identifiers).

Size

The size parameter is optional. It is used to set up the dimensions of a variable
array. The maximum number of array dimensions allowed in a Dim statement
is three (two if setting up an array of Strings). If you attempt to dimension a
variable higher than three dimensional, an error will occur.

For example:

Dim Flow(8,3,5) would create a three-dimensional array called Flow that has
8x3x5 or 120 elements.

Dim TCTemp(9) would create a one-dimensional array with 9 elements called
TCTemp.

The Option Base for dimensions is always 1; therefore, the lowest number in a
dimension is 1 and not 0. If a variable is dimensioned to a size that is too small
for its use in the program, a "Variable out of bounds" error will be returned
when the program is compiled by the datalogger.

As Type

The Dim instruction can be used with the optional As Type descriptor to
define the data format for the variable (e.g., DIM Flag1 As BOOLEAN). The
four data types are:

Float: The default IEEE4 data type; a 32-bit floating-point with a 24-bit
mantissa data type. Float gives a range of roughly -3x10^34 to 3x10^34 with
about seven digits of precision. If no data type is specified, Float is used.

Long: Sets the variable to a 32-bit long integer, ranging from -2,147,483,648
to +2,147,483,647 (31 bits plus the sign bit).

Boolean: Sets the variable to a 4-byte Boolean. Boolean variables are typically
used for flags and to represent conditions or hardware that have only 2 states

5-5

Advertising