04.01.2015 Views

CR1000 Manual - Campbell Scientific

CR1000 Manual - Campbell Scientific

CR1000 Manual - Campbell Scientific

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Section 7. Installation<br />

Variable Initialization<br />

By default, variables are set equal to zero at the time the datalogger program<br />

compiles. Variables can be initialized to non-zero values in the declaration.<br />

Examples of syntax are shown in CRBasic example Initializing Variables (p. 122).<br />

CRBasic Example 11.<br />

Initializing Variables<br />

Public aaa As Long = 1<br />

Public bbb(2) As String *20 = {"String_1", "String_2"}<br />

Public ccc As Boolean = True<br />

‘Initialize variable ddd elements 1,1 1,2 1,3 & 2,1.<br />

‘Elements (2,2) and (2,3) default to zero.<br />

Dim ddd(2,3)= {1.1, 1.2, 1.3, 2.1}<br />

‘Initialize variable eee<br />

Dim eee = 1.5<br />

Local Variables<br />

Local variables are variables that are reserved for use within the subroutines (p. 187)<br />

or functions (p. 525) in which they are declared as Dim. Names can be identical to<br />

globally declared variables and to variables declared locally in other subroutines<br />

and functions. This feature allows creation of a CRBasic library of reusable<br />

functions and subroutines that will not cause variable name conflicts. If a<br />

program with Dim variables declared locally attempts to use them globally, the<br />

compile error undeclared variable will occur.<br />

To make locally defined variable public, which makes them displayable, in cases<br />

where making them public will lead to a name conflict with other Public<br />

variables, create a data table to which the local variables are sampled, then display<br />

those sampled data.<br />

When passing the contents of a global variable to a local variable, or local to<br />

global, declare passing / receiving pairs with the same data types and applicable<br />

string lengths.<br />

7.7.3.4.2 Constants<br />

CRBasic example Using the Const Declaration (p. 123) shows use of the constant<br />

declaration. A constant can be declared at the beginning of a program to assign an<br />

alphanumeric name to be used in place of a value so the program can refer to the<br />

name rather than the value itself. Using a constant in place of a value can make<br />

the program easier to read and modify, and more secure against unintended<br />

changes. If declared using ConstTable / EndConstTable, constants can be<br />

changed while the program is running by using the external keyboard / display<br />

menu (Configure, Settings | Constant Table) or the C command in a terminal<br />

emulator (see Troubleshooting -- Terminal Emulator (p. 442) ).<br />

Note Using all uppercase for constant names may make them easier to recognize.<br />

122

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!