Introduction
An action is edited in the same way as a procedure in the editor window of the editor or in the Graphics Designer action editor.
For an action can be executed in runtime, it requires a trigger. Actions which are triggered by an event in Graphics Designer do not require the assignment of a trigger.
If an action is modified while runtime is active, the change is applied when the picture is reloaded (in the case of actions in Graphics Designer) or the next time the action is called (in the case of actions in Global Script).
Note:
A change in the code in runtime cannot be applied when another action is being carried out at the same time.
A procedure call can be inserted in the action by dragging the procedure from the editor's navigation window and dropping in the corresponding position of the code in the editor window. C scripts cannot be called in VBS actions.
Declaration Area in Actions
If you create actions in the Graphics Designer, you can display the declaration area of the action using the button. When a new action is created, the non-deletable instruction "Option explicit" is entered automatically in the declaration area. The instruction is necessary as it prevents errors caused by the incorrect notation of tags without declaration.
The instruction requires that the tags are always specified with the instruction "Dim"
in the code.
Do not use the "Option explicit" instruction in the code as this can cause runtime errors.
In the declaration area, you can also make general settings which you want to use globally for the current picture, e.g.:
• tag definitions
• procedures which you only want to use in this picture
Note:
Always make sure that the procedures in the declaration area have correct syntax, i.e. with "Sub" - "End Sub". Do not create directly executable codes in the
declaration area as this can cause runtime errors.
Note:
If global tags are used in the declaration area of actions Graphics Designer, note that the event-driven and cyclic/tag-driven actions are processed separately in runtime. There is no synchronization of global tags between the two runtime systems in runtime. If synchronization of the tags is necessary, it must be configured via WinCC tags.
When making definitions in the declaration area, pay attention to the structure of the Script files, as described under "Structure of VBScript files".
Functions for Editing Actions
The script editors provide the following functions to assist you in creating action code:
Intellisense and Highlight Syntax
During text entry, context-sensitive lists appear containing the properties, methods, and objects possible at the current code position. If you insert an element from the list, the required syntax is also indicated automatically.
Note:
Full intellisense for all objects can only be utilized in the Graphics Designer if the list is accessed using the object name and the result is assigned to a tag.
Otherwise, only a list of standard properties is offered.
Example of full intellisense:
Dim Variable
Set Variable = ScreenItems ("Circle1") Tag.<Intellisense>
If picture window limits are exceeded during addressing, it is once again only the standard properties which are offered since the picture of the picture window is not loaded.
General VBS Functions
Use the "Function List" context menu command in the editor window to display a list of general VBS functions.
Listing Objects, Properties and Methods
Using the context menu in the Editor window you can view a list of the possible objects by calling the "Object List" command in the Graphics Designer. Global Script only provides the HMIRuntime object in this list because there is no direct access to the objects of Graphics Designer.
Use the "Properties/Methods" context menu command to acquire a list of the possible properties and methods.
The same lists can be called in with the key combination <CTRL + Spacebar> but according to the context of the script.
Code Templates
In the "Code Templates" tab in the Navigation window of the Editor, you will find a selection of frequently used instructions, e.g. for loops and conditional instructions.
The templates can be inserted in the procedure codes by means of drag&drop.
If you insert a code template into your code, it is important to note that, for example, conditions in the templates are identified by "_XYZ_". You must replace these placeholders with the appropriate information.
Selection Dialogs
If WinCC tags or objects are used in the code, the following selection dialogs are available for use:
• Opens a tag selection dialog specifying the selected tag name as the return value.
• Opens a tag selection dialog and returns the tag name with an associated reference.
• Opens a picture/object browser in which a picture/object can be selected whose name is then used for the return value.
• Opens a picture selection dialog for pictures and returns the picture name, with sever prefix if necessary.
Syntax Check
Global Script supports you by providing a syntax check which you can perform after the code has been created. Syntax errors in the code are displayed in the output window of the editor. You can move to the erroneous point in the code directly by double-clicking the error in the output window.
Note:
The syntax check can only detect syntax errors in the code. Programming errors, such as missing references, only become visible in Runtime. Therefore, always check the scripts in the runtime environment and use a debugger, if necessary, to detect and eliminate errors. The way to test scripts with a debugger is described in this documentation under the topics "Diagnostics" > "Testing with the Debugger".
Procedure
Procedure
1 Open Global Script.
2 Double click on the action on the Action tab control in the navigation window.
3 Edit the action.