Specifications
Section 9. CR1000 Programming
9-6
9.6 Declarations
Constants (and pre-defined constants), Public variables, Dim variables, Aliases,
Units, Data Tables, Subroutines are declared at the beginning of a CRBASIC
program.
9.6.1 Variables
A variable is a packet of memory, given an alphanumeric name, through which
pass measurements and processing results during program execution.
Variables are declared either as Public or Dim at the discretion of the
programmer. Public variables can be viewed through the CR1000KD or
software numeric monitors. Dim variables cannot.
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. EXAMPLE 9.6-1 shows program code using a variable array to
red
uce the amount of code required to convert four temperatures from °C to °F.
EXAMPLE 9.6-1. CRBASIC Code: Using a variable array in calculations.
Public TempC(4)
Public TempF(4)
Dim T
BeginProg
Scan (1,Sec,0,0)
Therm107 (TempC(),4,1,Vx1,0,250,1.0,0)
For T = 1 To 4
TempF(T) = TempC(T) * 1.8 + 32
Next
NextScan
EndProg