VBScript (Visual Basic Scripting Edition) is a lightweight scripting language developed by Microsoft, designed specifically for automation and scripting tasks. It is widely used in HMI and SCADA environments—particularly in systems like WinCC SCADA—to automate repetitive operations such as tag value manipulation, alarm handling, visualization tasks, network error management, and administrative functions.
VBScript is known for its user-friendly syntax, making it easier to learn and implement compared to other scripting languages. Its foundation in Microsoft's Visual Basic language gives it a familiar structure for those already working with Microsoft technologies.
In WinCC, VBScript plays a crucial role in developing interactive and responsive graphical user interfaces (GUIs). It allows developers to write custom logic within Global Scripts or the Graphics Designer, enabling more dynamic and customized SCADA applications.
This article focuses exclusively on VBScript scripting within the WinCC SCADA environment, providing guidance and examples for engineers, integrators, and automation professionals.
A Sub defines a subroutine, which is a block of code designed to perform a specific task. Unlike a Function, a Sub does not return a value. Subroutines help organize your code into reusable sections.
Calling the subroutine executes the instructions inside it.
Summary:
A Global Script in WinCC SCADA is a reusable piece of code that can be accessed and executed anywhere within a project or even across multiple projects. When a VBScript is created as a global script, it allows you to centralize your automation logic, making it easier to maintain and reuse throughout your WinCC SCADA applications.
You can create and edit global scripts using the VBScript Editor within WinCC. To open the Global VBScript editor:
Within the Global Script, you can define the following types of code modules:
Using global VBScript in WinCC SCADA enhances modularity and reduces code duplication, which simplifies debugging and future updates. It also enables engineers to implement complex automation logic, alarms, data processing, and user interface customization efficiently.
To create a global VBScript action in WinCC SCADA, open the Global Script Editor and create a simple action. In this example, we add two numerical values and display the result using a message box.
The subroutine addvalue takes two input values, adds them together, and shows the sum in a pop-up message box. This demonstrates how you can write reusable scripts that perform calculations and interact with users through the graphical interface.
By using global VBScript actions, you can easily call such functions anywhere in your project, promoting code reusability and simplifying maintenance.
You can add VBScript directly in the Graphics Designer of WinCC SCADA to enhance interactivity. In the Graphics Designer, you can execute VBScript functions or actions triggered by events such as mouse clicks, button presses, focus changes, hover events, and more.
Additionally, you can use global scripts within graphics objects to centralize and reuse your code across the project. To add a VBScript to a graphic object, simply select the object (for example, a button), then select the desired event such as a mouse click. Right-click on the event and choose the option to assign a VBScript action.
Open the VBScript editor in Graphics Designer as described in the previous steps. In this example, we create a simple script to check whether the entered value is even or odd. If the value is even, a message box will appear displaying the message "Entered value is even". Similarly, if the value is odd, a message box will display "Entered value is odd".
This VBScript subroutine named OnClick is designed to run when a user triggers an event, such as clicking a button in the WinCC SCADA Graphics Designer.
Inside the script, two variables are declared: value1 and tagvalue. The HMIRuntime.Tags("input") function is used to access a WinCC tag named input. This tag is assigned to the variable tagvalue.
The script then reads the current value of the tag using tagvalue.Read and stores it in the variable value1. Using the Mod operator, the script checks whether the value is divisible by 2. If the remainder is zero, it displays a message box saying "Value is even". Otherwise, it shows "Value is odd".
This script demonstrates how to dynamically read data from the SCADA system and use logic to provide real-time feedback to the operator or engineer through message boxes.