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

AVEVA™ Plant SCADA

Integrating VBA into a Project

  • Last UpdatedJul 18, 2023
  • 3 minute read

You can integrate VBA into your Plant SCADA project in two ways:

In either case, all procedures within a VBA script can access (read and write) any Plant SCADA variable tag in the same way Cicode can access Plant SCADA tags.

Access Cicode Tags with VBA

VBA can use your Plant SCADA project variable tag and alarm tag variables in the same way as could Cicode (except for syntax differences). Both programming languages refer to a project's variable tags by using the name of the tags as defined in the project.

For instance, in the following example, two variable tags in your Plant SCADA project may be named B1_PUMP_101_SP and B1_PUMP_101_PV respectively, representing the Set Point and Process Variable values of Pump 101. These variable tag names can be used within a VBA statement (just as you would use any other variable in VBA). Both values can be read-from and written-to directly using VBA:

' set pump speed to 500 rpm
B1_PUMP_101_SP = 500
' calculate pump speed error
Dim varPumpSpeedError
varPumpSpeedError = B1_PUMP_101_PV - B1_PUMP_101_SP

You should note that VBA does not recognize Plant SCADA variable tags that are named with an initial digit (0-9).

To access such tags using VBA, you must precede the tag name with a case-insensitive string containing the letters 'V', 'B,' and the underscore character (VB_) as in the following example:

Plant SCADA Tag Name: "123Pump"
CitectVBA reference "VB_123Pump"

For details of using tags that have a number as their first digit in your project, consider using the [General]TagStartDigit Citect.ini parameter.

Access Plant SCADA Array Values with VBA

To access Plant SCADA Array Values in VBA use the following format:

<TagName>.<Index>(<indexNumber>)

Where:

  • <TagName> = The name of the array

  • <Index> = The function that retrieves the values located at the specified <indexNumber>

  • <indexNumber> = Position of the array to read/write the value.

Example

In this example, an array is declared with name "sampleArray" in Plant SCADA Studio with 10 elements.

  • To read the value at index 2 from sampleArray use the following syntax:

    sampleArray.Index(2)

  • To write to the value at index 3 in sampleArray use the following syntax:

    sampleArray.Index(3) = 4

Access ActiveX Objects with VBA

ActiveX objects which have been added to a graphics page in your Plant SCADA project can be referred to in VBA by constructing a unique reference name using the page name, the underscore character, the letters 'AN', and the animation number of the object.

This reference name is called the Event Class name in Plant SCADA. To view the reference name, double-click the ActiveX object, select the Access tab, then click the Identification tab.

Example

In this example, the reference name for the Temperature meter object would be referred to in VBA as ActiveX_AN125.

All object properties can be accessed and manipulated using VBA in the same way that object properties can be manipulated using Cicode.

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