Appendix B. Introduction to CRBasic Programming
B-6
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.
CRBasic Example B-4. 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
'degrees C to degrees F.
Public
TempC(4)
Public
TempF(4)
Dim
T
BeginProg
Scan
(1,Sec,0,0)
Therm107
(TempC(1),1,1,Vx1,0,400,1.0,0)
Therm107
(TempC(2),1,2,Vx1,0,400,1.0,0)
Therm107
(TempC(3),1,3,Vx2,0,400,1.0,0)
Therm107
(TempC(4),1,4,Vx2,0,400,1.0,0)
For
T = 1
To
4
TempF(T) = TempC(T) * 1.8 + 32
Next
T
NextScan
EndProg
B.2.3 Conserving Program Memory
One or more of the following memory-saving techniques can be used on the
rare occasions when a program reaches memory limits:
•
Declare variables as
DIM
instead of Public.
DIM
variables do not
require buffer memory for data retrieval.
•
Reduce arrays to the minimum size needed. Arrays save memory over
the use of scalars as there is less metadata required per value.
•
Use variable arrays with aliases instead of individual variables with
unique names. Aliases consume less memory than unique variable
names.
•
Confine string concatenation to
DIM
variables.
•
Dimension string variables only to the size required.
B.3 Constants
Constants are discrete packets of CR300 memory that store specific values that
do not vary during program execution. A constant can be declared at the
beginning of a program to assign an alphanumeric name to a value. The
program can then refer to the name rather than the value itself. Using a constant
in place of a value can make the program easier to read and modify, and more
secure against unintended changes. Following is an example of declaring a
constant:
Const
CtoF_Mult = 1.8
Содержание CR300 series
Страница 2: ......
Страница 6: ......
Страница 68: ...CR300 Series Datalogger 58...
Страница 70: ......
Страница 85: ......