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

AVEVA™ Plant SCADA

Multithread Considerations with VBA

  • Last UpdatedJul 18, 2023
  • 2 minute read

Cicode is pre-empted and executed on an instruction-by-instruction basis. This means that execution of a simple unnested Cicode thread can only switch to another thread after the current Cicode instruction has completed execution.

VBA code is pre-empted and executed on a line-by-line basis (as opposed to an instruction-by-instruction basis), and pre-empting can only occur after the current line has completed execution.

Each line of VBA script is handled as a separate thread in Plant SCADA. Therefore multiple procedures placed on one line may not complete before another subsequent thread is processed in a multithreading environment. This could cause unpredictable results and consequences, including data invalidation and corruption.

UNINTENDED EQUIPMENT OPERATION

  • Create your VBA program so that every code statement is positioned on a unique line.

  • Do not group more than one code statement on a single line in your program. Grouping VBA statements on a single line can cause data corruption during multithreaded execution.

Failure to follow these instructions can result in death, serious injury, or equipment damage.

If, for example, you were reading or setting some variable or point in a multi-statement thread, and further processing that data in a later thread,that data might become invalid or incorrect. For this reason, you should separate every statement onto separate lines in VBA.

For example, it is better to write:

A = Motor1.speed() + Motor4.speed() + Motor5.speed()

as

A = Motor1.speed()
A = A + Motor4.speed()
A = A + Motor5.speed()

in situations where the method speed()may take a long time to execute.

In the first example above, the VBA thread executes for three times longer before it can be pre-empted than in the latter example.

Note: This does not apply to Cicode because the Cicode engine can pre-empt aggregated code.

See Also

Using VBA in Command or Expression Fields

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