beautypg.com

1 arrays – Campbell Scientific CR200/CR200X-series Dataloggers User Manual

Page 86

background image

Section 9. Programming

Variable names can be up to 16 characters in length, but most variables should

be no more than 12 characters long. This allows for the 4 additional characters

that are added as a suffix to the variable name when it is output to a data table.

Variable names cannot start with a number or contain spaces or quote marks (“),

but can contain numbers and underscores (_). Several variables can be declared

on a single line, separated by commas:

Public RefTemp, AirTemp2, Batt_Volt

9.6.1.1 Arrays

When a variable is declared, several variables of the same root name can also be

declared. This is done by placing a suffix of "(x)" on the alphanumeric name,

which creates an array of x number of variables that differ only by the

incrementing number in the suffix. For example, rather than declaring four

similar variables as follows,

Public TempC1

Public TempC2

Public TempC3

Public TempC4

simply declare a variable array as shown below:

Public TempC(4),

This creates in memory the four variables TempC(1), TempC(2), TempC(3),

and TempC(4).

A variable array is useful in program operations that affect many variables in the

same way.

CRBASIC EXAMPLE. Using a Variable Array in Calculations

(p.

74) shows program code using a variable array to reduce the amount of code

required to convert four temperatures from Celsius degrees to Fahrenheit

degrees.

In this example a For/Next structure with a changing variable is used to specify

which elements of the array will have the logical operation applied to them. The

CRBASIC For/Next function will only operate on array elements that are clearly

specified and ignore the rest. If an array element is not specifically referenced,

e.g., TempC(), CRBASIC references only the first element of the array,

TempC(1).

74