beautypg.com

Campbell Scientific CR9000X Measurement and Control System User Manual

Page 176

background image

Section 5. Program Declarations

(e.g., On/Off, Ports). A Boolean variable uses the same 32-bit long integer
format as a Long but can set to only one of two values: True, which is
represented as –1, and false, which is represented with 0.

String * size: Sets the variable to a string of ASCII characters, NULL
terminated, with size specifying the maximum number of characters in the
string (note that the null termination character counts as one of the characters
in the string). The size argument is optional. The minimum string size, and the
default if size is not specified, is 16 (15 usable bytes and 1 terminating byte).
String size is allocated in multiples of 4 bytes. Thus, a string declared as 18
bytes will actually be 20 bytes (19 usable bytes and 1 terminating byte). A
string is convenient in handling serial sensors, dial strings, text messages, etc.

As a special case, a string can be declared as String * 1. This allows the
efficient storage of a single character. The string will take up 4 bytes in
memory and when stored in a data table, but it will hold only one character.

Strings can be dimensioned only up to 2 dimensions instead of the 3 allowed
for other data types. (This is because the least significant dimension is actually
used as the size of the string.) To begin reading or modifying a string at a
particular location into the string, enter the location or begin reading a string at
a particular character, enter the character as a third dimension; e.g.,
String(x,y,n) where n is the desired character.

See Section 4.2.4.5 Data Type Operational Detail for in-depth discussion
about the data types supported by the CR9000X.

Initialize

Variables can be initialized when declared. For example:

Dim MyVar = 3.5 or Dim MyVar = {3.5}

Dim MyArray(3) = {3, 6, 9}

The braces are optional if a scalar is being initialized or if only the first
variable in an array is being initialized.

When declaring a data type for the variable, the variable is declared before
initialization:

Dim StringVar as String * 30 = "Test String"

For all arrays, including multi-dimensional arrays, the least significant
elements are initialized first. In other words, if the array is not fully initialized,
the first elements will be initialized first, and the remainder will be initialized
to the default value of 0:

Dim Array (2,3) = (1,2,3,4)

Results in ,

Array(1,1) = 1
Array(1,2) = 2
Array(1,3) = 3
Array(2,1) = 4
Array(2,2) = 0
Array(2,3) = 0

5-6