beautypg.com

2 constants, 1 predefined constants, Crbasic example 5. flag declaration and use – Campbell Scientific CR200/CR200X-series Dataloggers User Manual

Page 88: Crbasic example 6. using the const declaration

background image

Section 9. Programming

CRBASIC EXAMPLE 5.

Flag Declaration and Use

Public batt_volt

Public Flag

BeginProg

Scan (1,Sec)

Flag = IIF (Flag=0,0,-1)

If Flag = true Then

Battery (batt_volt)

EndIf

NextScan

EndProg

9.6.2 Constants

CRBASIC EXAMPLE. Using the Const Declaration

(p. 76) shows use of the

constant declaration. A constant can be declared at the beginning of a program

to assign an alphanumeric name to be used in place of a value so the program

can 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.

Note Using all uppercase for constant names may make them easier to

recognize.

CRBASIC EXAMPLE 6.

Using the Const Declaration

Public PTempC, PTempF

Const CtoF_Mult = 1.8

Const CtoF_Offset = 32

BeginProg

Scan (1,Sec,0,0)

Therm109 (PTempC,1,1,Ex1,1.0,0)

PTempF = PTempC * CtoF_Mult + CtoF_Offset

NextScan

EndProg

9.6.2.1 Predefined Constants

Several words are reserved for use by CRBASIC. These words cannot be used

as variable or table names in a program. Predefined constants include some

instruction names, as well as valid alphanumeric names for instruction

parameters. In general, instruction names should not be used as variable,

constant, or table names in a datalogger program, even if they are not

specifically listed as a predefined constant. If a predefined constant, such as

"Sub" is used as a variable in a program, an error similar to the following may

be, but is not always, displayed at CRBASIC pre-compile.

Compile Failed!

line 8: Sub is already is use as a predefined CONST.

76