Constants

The Const declaration is used to assign a name that can be used in place of a value in the data logger CRBasic program. Once a value is assigned to a constant, 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 the keyboard display, the C command in terminal mode, or via a custom menu.

Constants can also be typed For example: Const A as Long = 9999, and Const B as String = “MyString”. Valid data types for constants are: Long, Float, Double, and String. Other data types return a compile error.

When the CRBasic program compiles, the compiler determines the type of the constant (Long, Float, Double, or String) from the expression. This data type is communicated to the software. The software formats or restricts the input based on the data type communicated to it by the data logger.

You can declare a constant with or without specifying a data type. If a data type is not specified, the compiler determines the data type from the expression. For example:  Const A = 9999 will use the Long data type. Const A = 9999.0 will use the Floatdata type.