CitectVBA Programming Reference > Understanding CitectVBA Language Basics > Constants > Declaration of constants

Declaration of constants

CitectVBA constants can only be declared and referenced within CitectVBA file modules. CitectVBA modular constants have modular scope and cannot be referenced (accessed and used) from outside their CitectVBA module (file).

Note: CitectVBA constants cannot be used directly in CitectSCADA command or expression fields.

Once declared within a CitectVBA module, CitectVBA constants can be referenced and used in any procedure within the same code module. A constant declared outside a procedure has modular scope to all procedures within that same CitectVBA module (file). See Scope of CitectVBA. Constants declared in a Sub or Function procedure have local scope only within that procedure.

CitectVBA constants are declared with the Conststatement in the following format.

Const <ConstantName> [ As <DataType> ] = <expression>


If no data type is declared, CitectVBA automatically assigns one of the following data types to the constant:

Constant statements can only be declared and assigned using simple expressions. Constants cannot be assigned values from variables, user-defined functions, intrinsic CitectVBA functions (such as Chr), or from any expression that involves an operator. A constant needs to be defined before it can be used.


' Correct declaration examples
Const Seven = 7

' long assignment
Const Pi = 3.14159

' double assignment
Const Lab = "Laboratory"

' string assignment
' Incorrect declaration examples. Note that the following declarations demonstrate incorrect assignments because each contains an operator
Const conPi = 4 * Atn(1)
' will cause a CitectVBA compile error
Const conDegToRad = (conPi / 180)
' will cause a CitectVBA compile error

For an example of using constants in CitectVBA, see Constants.

Note: The use of Global, Public, and Private keywords has no effect on scope in CitectVBA.

See Also


Intrinsic constants


CitectVBA Data Types

CitectVBA Function Reference