Your CitectVBA code may contain frequently recurring constant values like Pi, or may contain numbers that are difficult to remember or have no obvious meaning. You can make your CitectVBA code much easier to read and maintain using constants to represent those values.
Unlike variables, constants can't be changed once your CitectSCADA project is compiled and running. Constants are either symbolic or intrinsic:
const
statement.You can create a constant in CitectVBA named
Pi
, assign it the numeric value
once in your code, then refer to it by using the constant name, as
shown here:
'modular level constant declaration
Const Pi = 3.1415926
Function CircleArea(Byval Radius)
' calculate and return area of circle
' using radius passed in as argument
CircleArea = Pi * (Radius * Radius)
End Function
Function CircleCircumference(Byval Radius)
' calculate and return circumference of circle
' using radius passed in as argument
CircleCicumference = Pi * Radius * 2
End Function
These CitectVBA functions would be called from a CitectSCADA command or expression field like this:
CiVBA
TestTag_1 = CircleArea(TestTag_1)
or
CiVBA
TestTag_1 = CircleCircumference(TestTag_1)
See Also
Passing variables Byref and Byval
Integrating CitectVBA with CitectSCADA