Const (Assign a Name to a Value)

The Const declaration is used to assign a name that can be used in place of a value in the datalogger program.

Syntax

Const ConstantName = Expression

Remarks

Once a value is assigned to a constant using the Const declaration, each time the value is needed in the program, the programmer can type in the constant name instead of the value itself. The use of the Const declaration can make the program easier to follow, easier to modify, and more secure against unintended changes. Unlike variables, constants cannot be changed while the program is running.

Constants must be defined before they are used in the program. Constants can be defined in a ConstTable/EndConstTable construct allowing them to be changed using softwarethe keyboard display, or the C command in terminal mode, or via a custom menu.

Constants can also be typed (Const A as Long = 9999, Const B as String = “MyString”). Valid data types for constants are: ClosedLong Data type used when declaring a variable as an integer., ClosedFloat Four-byte floating-point data type. Default datalogger data type for Public or Dim variables. Same format as IEEE4., Double, and ClosedString A data type used when declaring a variable consisting of alphanumeric characters.. Other data types return a compile error. If constants are not typed, the data type will be set according to the value of the constant:

Const MyLong = 0  'data type = Long

Const MyFloat = 0.0  'data type = Float

Const MyString = "text"  'data type = String

Beginning with OS 39, t The Const declaration can be an array of values signaled by a comma separated list of values enclosed by {}; For example:

Const A = {1,2,3,4,5,6,7,8,9,10}, SerialOutBlock(ComRS232,A,10)

The Const statement includes:

Parameters

ConstantName

Name of the constant.

Expression

Expression assigned to the constant. The expression can consist of literals (such as 1.0), a string, other constants, or any of the arithmetic or logical operators.

Only one constant can be defined with each Const declaration. Unlike other similar languages, CRBasic does not allow multiple constants to be defined with one declaration.