VBA is a powerful scripting tool integral to DeltaV Operate. Many features of DeltaV Operate allow you to use VBA more effectively. This chapter presents many options that help you build your projects more easily.
DeltaV Operate includes several subroutines that can help simplify scripts that are intended to perform common tasks, such as acknowledging alarms or replacing pictures. Since these subroutines are stored in the FactoryGlobals project, they can be accessed directly through the Visual Basic Editor. For more information on FactoryGlobals, see Creating Global Scripts.
In addition to providing the code necessary to perform the task at hand, subroutines offer several "extras" that you would normally have to code yourself, including:
Generic error handling.
Posting of operator messages to the alarm system.
Conformance to VBA naming conventions.
If you are using tag names that contain special characters, this is a perfect case for using the ReadValue and WriteValue global subroutines to access your tags in VBA.
For example, suppose you have the following tag:
Fix32.SCADA.SORTER|SIZER|BLOCK10|PT.F_CV
In VBA, you can read this tag with the following syntax:
Private Sub Text1_Click()
Dim x As Variant
x = ReadValue("Fix32.SCADA.SORTER|SIZER|BLOCK10|PT.F_CV")
Text1.Caption = x
End Sub
Once the value is stored as a variant (x), you can use it in expressions.
In some cases, you may need to handle the sending of operator messages in your own scripts. For example, a subroutine may not exist for the exact task that you want to perform. The following is an example of a specific case involving the frsWriteValue subroutine.
As stated in the previous section, subroutines handle the posting of operator messages to alarm areas for you. Therefore, the following script:
frsWritevalue "1", "dummy"
will send out this message:
dvsys.dummy.f_cv was set to 1.
However, this script will not generate an operator message:
dvsys.dummy.f_cv=1
A separate subroutine, SendOperatorMessage, is provided for that purpose. Simply add a call to the SendOperatorMessage to generate the desired message.
frsWriteValue, frsReadValue, SendOperatorMessage, and all other DeltaV Operate subroutines are described in more detail in the Automation Interfaces Help file.
The code within the global subroutines offers a wealth of information to the developer who is learning how to automate DeltaV Operate with VBA. Realizing this, all of the code within these subroutines has been exported to a text file entitled globalsubroutines.txt (located in the \DeltaV\iFIX\NLS path) for your convenience.
DeltaV Operate also provides several Experts to help you perform the most common functionality. Just as subroutines offer help to the seasoned VBA programmer, Experts can help developers who want to achieve similar results without having to write any VBA code at all. These Experts, which look like standard dialog boxes, actually generate VBA code for you, based on how you configured the options within the Expert.
You can use keyboard accelerators, key sequences that allow you to perform a function, to fire scripts using the KeyUp or KeyDown events. However, the built-in keyboard accelerators take precedence over any KeyUp or KeyDown events in the picture or user area. Therefore, you should avoid using keyboard accelerators that conflict with those that are reserved for internal use. The following table lists all of the reserved accelerators in the run-time and configuration environments.
|
Keyboard Accelerator |
Purpose |
Works in Run-time Mode |
Works in Configure Mode |
|---|---|---|---|
|
F1 |
Invokes Help. |
No |
Yes |
|
F10, Ctrl + F10, Alt (alone) |
Activates the WorkSpace menu bar. |
Yes |
Yes |
|
Ctrl + F4 |
Closes document. |
Yes |
Yes |
|
Ctrl + W |
Toggles between configuration or run-time environment. |
Yes |
Yes |
|
Ctrl + O |
Activates Open File dialog. |
Yes |
Yes |
|
Ctrl + P |
Activates Print File dialog. |
Yes |
Yes |
|
Ctrl + Esc |
Activates Windows Start menu (unless disabled through security). |
Yes |
Yes |
|
Ctrl + Break, Ctrl + Alt +Break |
Breaks script execution. |
Yes |
No |
|
Ctrl + Alt + Esc, Ctrl + Alt + Shift + Esc |
Window becomes inactive (unless disable through security). |
Yes |
Yes |
|
Ctrl + Alt + Del |
Opens Windows Login dialog (unless disabled through security). |
Yes |
Yes |
|
All Alt key combinations |
Activates the WorkSpace menu. |
Yes |
Yes |
|
Shift + letter combinations |
Alphanumeric data entry (could trigger when entering an uppercase letter). |
Yes |
Yes |
|
Ctrl + A |
Selects all |
No |
Yes |
|
Ctrl + C |
Copies |
No |
Yes |
|
Ctrl + D |
Duplicates |
No |
Yes |
|
Ctrl + F |
Finds and replaces |
No |
Yes |
|
Ctrl + O |
Opens document |
Yes |
Yes |
|
Ctrl + P |
Prints document |
Yes |
Yes |
|
Ctrl + S |
Saves document |
No |
Yes |
|
Ctrl + V |
Pastes from the clipboard |
No |
Yes |
|
Ctrl + Z |
Undoes the last action |
No |
Yes |