Section 7. Installation
(x)
on the variable name. X number of variables are created that differ in name
only by the incrementing number in the suffix. For example, the four statements
Public
TempC1
Public
TempC2
Public
TempC3
Public
TempC4
can simply be condensed to
Public
TempC(4).
This statement 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. 136)
shows compact code that converts four temperatures (°C) to °F.
In this example, a
For/Next
structure with an incrementing 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, as is the case in the declaration
Dim TempC()
CRBasic references only the first element of the array,
TempC(1)
.
See CRBasic example
Concatenation of Numbers and Strings
(p. 284)
for an
example of using the
+=
assignment operator
(p. 565)
when working with arrays.
CRBasic Example 6.
Using a Variable Array in Calculations
'This program example demonstrates the use of a variable array to reduce code. In this
'example, two variable arrays are used to convert four temperature measurements from
'degree C to degrees F.
Public
TempC(4)
Public
TempF(4)
Dim
T
BeginProg
Scan
(1,Sec,0,0)
Therm107
(TempC(),1,1,Vx1,0,250,1.0,0)
Therm107
(TempC(),1,2,Vx1,0,250,1.0,0)
Therm107
(TempC(),1,3,Vx1,0,250,1.0,0)
Therm107
(TempC(),1,4,Vx1,0,250,1.0,0)
For
T = 1
To
4
TempF(T) = TempC(T) * 1.8 + 32
Next
T
NextScan
EndProg
7.8.4.5 Declaring Local and Global Variables
Advanced programs may use
subroutines
(p. 288)
or
functions
(p. 602),
each of which
can have a set of
Dim
variables dedicated to that subroutine or function. These
136
Summary of Contents for CR1000
Page 2: ......
Page 4: ......
Page 6: ......
Page 32: ......
Page 36: ......
Page 38: ......
Page 40: ......
Page 60: ...Section 4 System Quickstart Figure 16 PC200W View Line Graph 60 ...
Page 96: ......
Page 98: ...98 ...
Page 302: ......
Page 453: ...Section 8 Operation Figure 115 Using the Keyboard Display 453 ...
Page 456: ...Section 8 Operation Figure 118 Real Time Custom 456 ...
Page 457: ...Section 8 Operation 8 8 1 3 Final Memory Tables Figure 119 Final Memory Tables 457 ...
Page 458: ...Section 8 Operation 8 8 2 Run Stop Program Figure 120 Run Stop Program 458 ...
Page 460: ...Section 8 Operation Figure 122 File Edit 460 ...
Page 461: ...Section 8 Operation 8 8 4 PCCard Memory Card Display Figure 123 PCCard CF Card Display 461 ...
Page 478: ......
Page 506: ......
Page 536: ......
Page 636: ......
Page 642: ......
Page 644: ......
Page 676: ......
Page 677: ......