Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Plant SCADA

Constants

  • Last UpdatedJul 18, 2023
  • 1 minute read

Your VBA 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 VBA code much easier to read and maintain using constants to represent those values.

Unlike variables, constants can't be changed once your Plant SCADA project is compiled and running. Constants are either symbolic or intrinsic:

  • Symbolic or user-defined constants are declared by using the const statement.

  • Intrinsic constants are provided in object libraries of ActiveX objects and you cannot use them in VBA: they cause compile errors as there is no way to provide early-binding to the object type library.

You can create a constant in VBA 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 VBA functions would be called from a Plant SCADA command or expression field like this:

CiVBA
TestTag_1 = CircleArea(TestTag_1)

or

CiVBA
TestTag_1 = CircleCircumference(TestTag_1)

See Also

Declaration of Constants

Passing Variables Byref and Byval

Integrating VBA into a Project

Intrinsic Constants

Scope of VBA

VBA Function Reference

TitleResults for “How to create a CRG?”Also Available in