Learning Foundation: Dynamic Graphics
This page has one defined job in the WinCC VBScript learning path. Master this foundation before using the same concept inside larger SCADA, SQL Server and reporting scripts.
Tag reading, conditions and error diagnostics.
Graphics scripts should translate validated process state into clear object properties such as color, visibility, text and position.
Animate furnace motor/fan/status objects from SQF process tags and internal states.
Control WinCC screen-object properties through structured scripts without mixing unsafe equipment control into animation code.
Read validated tag/status
Map state to display rule
Resolve named object
Change visual behavior
Operator sees state
Complete WinCC VBScript Learning Path
Use Previous/Next for the recommended practical order, or open any topic below as a reference.
Control WinCC Graphics Designer Objects with VBScript
Complete this practical lab to create internal HMI tags and control WinCC Graphics Designer object color, visibility, position, text and operator actions with VBScript.
HMIRuntime, ScreenItems and PDL examples on this page target SIMATIC WinCC Classic/Professional VBS. WinCC Unified uses JavaScript. WinCC Comfort/Advanced and individual WinCC releases can use different event signatures and object properties; verify each example in the installed Siemens help.1. Lab objective and software requirements
The objective is to create HMI internal tags and use VBScript in WinCC Graphics Designer to control object properties and respond to operator events. The completed screen demonstrates process-state colors, show/hide behavior, command writing, level animation, status text, popup navigation, alarm indication, permission-aware controls and a reusable project function.
Software and project requirements
- SIMATIC WinCC Classic/Professional with VBS support
- WinCC Graphics Designer and Tag Management
- A backed-up training project with Runtime simulation available
- Permission to create internal tags, pictures and project functions
2. Create the WinCC internal tags
In Tag Management, right-click Internal Tags, create each tag below and confirm its data type before using it in a script.
| No. | Tag name | Data type | Default | Purpose |
|---|---|---|---|---|
| 1 | Tag_Temperature | Integer | 0 | Simulated temperature |
| 2 | Tag_TankLevel | Integer | 0 | Tank level from 0 to 100 |
| 3 | Tag_MotorStart | Binary | 0 | Motor command for training |
| 4 | Tag_PumpStatus | Integer | 0 | Pump state 0, 1 or 2 |
| 5 | Tag_Alarm | Binary | 0 | Alarm indication flag |
- Open Tag Management.
- Right-click Internal Tags and select New Tag.
- Enter the exact tag name and select the specified data type.
- Save the tag and repeat for the remaining entries.
- Confirm all default values before starting Runtime.
3. Build the Graphics Designer practice screen
Create the picture Lab_VBS.pdl. Add the following objects and assign the exact configured names through Properties > General > Object Name.
| Object name | Object type | Lab purpose |
|---|---|---|
Rectangle1 | Rectangle | Temperature-state color |
GroupObject1 | Group or graphic object | Show/hide demonstration |
Button1 | Button | Operator event and tag write |
Rectangle_Level | Rectangle | Tank-level movement |
StaticText1 | Static Text | Dynamic pump-state text |
Rectangle_Alarm | Rectangle | Alarm indication |
Button_Popup | Button | Popup navigation |
4. Change object color from a process value
Attach to: Rectangle1 background-color dynamic. Use the active-picture object reference required by the installed WinCC release.
Sub OnPropertyTrigger()
Dim lValue
lValue = HMIRuntime.Tags("Tag_Temperature").Read
If lValue > 80 Then
ScreenItems("Rectangle1").BackColor = RGB(255, 0, 0)
ElseIf lValue > 50 Then
ScreenItems("Rectangle1").BackColor = RGB(255, 255, 0)
Else
ScreenItems("Rectangle1").BackColor = RGB(0, 255, 0)
End If
End Sub
Easy TestEasy Test 1 — InputBox + MsgBox
Simulation first; then run the original Graphics Designer code in WinCC Runtime.
Dim TestState
TestState = InputBox("Enter test state: 1 = ON / 0 = OFF", "Easy Test 1 — InputBox + MsgBox", "1")
If TestState = "1" Then
MsgBox "Expected Runtime result: object/screen should show the ACTIVE state.", vbInformation, "Graphics Quick Test"
Else
MsgBox "Expected Runtime result: object/screen should show the INACTIVE state.", vbInformation, "Graphics Quick Test"
End IfTest: enter values below 50, between 51 and 80, and above 80. Confirm the normal, warning and alarm states. Also provide a text or symbol cue so color is not the only indication.
5. Show or hide an object from a button event
Attach to: Button1 mouse-click event.
Sub OnClick(ByVal Item)
Dim bCurrentState
bCurrentState = ScreenItems("GroupObject1").Visible
ScreenItems("GroupObject1").Visible = Not bCurrentState
End Sub
Easy TestEasy Test 2 — InputBox + MsgBox
Simulation first; then run the original Graphics Designer code in WinCC Runtime.
Dim TestState
TestState = InputBox("Enter test state: 1 = ON / 0 = OFF", "Easy Test 2 — InputBox + MsgBox", "1")
If TestState = "1" Then
MsgBox "Expected Runtime result: object/screen should show the ACTIVE state.", vbInformation, "Graphics Quick Test"
Else
MsgBox "Expected Runtime result: object/screen should show the INACTIVE state.", vbInformation, "Graphics Quick Test"
End IfTest two consecutive clicks and verify that the group alternates between visible and hidden without affecting unrelated objects.
6. Write an internal tag on button click
Attach to: a dedicated motor-start training button. Avoid assigning two independent OnClick scripts to the same event.
Sub OnClick(ByVal Item)
Dim lWriteValue
lWriteValue = 1
HMIRuntime.Tags("Tag_MotorStart").Write lWriteValue
HMIRuntime.Trace "Motor Start training command sent" & vbCrLf
End Sub
Easy TestEasy Test 3 — InputBox + MsgBox
Write is simulated to avoid accidental equipment commands during beginner testing.
Dim TestValue
TestValue = InputBox("Enter value to test for WinCC tag: Tag_MotorStart", "Easy Test 3 — InputBox + MsgBox", "1")
If TestValue = "" Then
MsgBox "Test cancelled.", vbInformation, "Tag Write Quick Test"
Else
MsgBox "SIMULATION ONLY" & vbCrLf & _
"Tag: Tag_MotorStart" & vbCrLf & _
"Value that would be written: " & TestValue & vbCrLf & vbCrLf & _
"After checking interlocks, use the original .Write code above in Runtime.", _
vbInformation, "Tag Write Quick Test"
End IfConfirm that the internal tag becomes 1 and the trace message appears. A real motor command must be validated by PLC mode, permission, interlock and acknowledgement logic.
7. Animate a tank-level object
Attach to: the position dynamic for Rectangle_Level. Clamp the simulated input before calculating the Y coordinate.
Sub OnPropertyTrigger()
Dim lLevel, lPositionY
lLevel = HMIRuntime.Tags("Tag_TankLevel").Read
If lLevel < 0 Then lLevel = 0
If lLevel > 100 Then lLevel = 100
lPositionY = 200 - (lLevel * 1.5)
ScreenItems("Rectangle_Level").Top = lPositionY
End Sub
Easy TestEasy Test 4 — InputBox + MsgBox
Simulation first; then run the original Graphics Designer code in WinCC Runtime.
Dim TestState
TestState = InputBox("Enter test state: 1 = ON / 0 = OFF", "Easy Test 4 — InputBox + MsgBox", "1")
If TestState = "1" Then
MsgBox "Expected Runtime result: object/screen should show the ACTIVE state.", vbInformation, "Graphics Quick Test"
Else
MsgBox "Expected Runtime result: object/screen should show the INACTIVE state.", vbInformation, "Graphics Quick Test"
End IfTest 0%, 50% and 100%, then test values outside the expected range. Confirm the rectangle remains inside the designed movement area.
8. Display dynamic pump-status text
Attach to: the text dynamic for StaticText1.
Sub OnPropertyTrigger()
Dim lStatus
lStatus = HMIRuntime.Tags("Tag_PumpStatus").Read
Select Case lStatus
Case 0
ScreenItems("StaticText1").Text = "Pump OFF"
Case 1
ScreenItems("StaticText1").Text = "Pump ON"
Case 2
ScreenItems("StaticText1").Text = "Pump FAULT"
Case Else
ScreenItems("StaticText1").Text = "Pump status invalid"
End Select
End Sub
Easy TestEasy Test 5 — InputBox + MsgBox
Simulation first; then run the original Graphics Designer code in WinCC Runtime.
Dim TestState
TestState = InputBox("Enter test state: 1 = ON / 0 = OFF", "Easy Test 5 — InputBox + MsgBox", "1")
If TestState = "1" Then
MsgBox "Expected Runtime result: object/screen should show the ACTIVE state.", vbInformation, "Graphics Quick Test"
Else
MsgBox "Expected Runtime result: object/screen should show the INACTIVE state.", vbInformation, "Graphics Quick Test"
End IfThe Case Else state prevents an old caption from remaining visible when the status value is invalid.
9. Open a popup picture
Create PopupScreen.pdl first. Popup APIs differ across WinCC editions, so use the picture-window or popup method documented for the installed release. The following is a version-dependent template:
Sub OnClick(ByVal Item)
Dim sScreenName
sScreenName = "PopupScreen.pdl"
'Apply the supported popup or picture-window method for this WinCC release.
HMIRuntime.Trace "Popup requested: " & sScreenName & vbCrLf
End Sub
Easy TestEasy Test 6 — InputBox + MsgBox
Self-contained procedure test; no PLC or SQL Server is required.
Sub ShowSQFValue(ByVal NameText, ByVal ValueText)
MsgBox NameText & " = " & ValueText, vbInformation, "Sub Quick Test"
End Sub
Dim TempAct
TempAct = InputBox("Enter Temp_Act", "Easy Test 6 — InputBox + MsgBox", "825.5")
Call ShowSQFValue("Temp_Act", TempAct)Verify screen existence, user permission, position, modal behavior and close behavior before commissioning. Continue with WinCC screen navigation, faceplates and reusable instances.
10. Create a cyclic alarm indication
Attach to: the visibility dynamic for Rectangle_Alarm, using an approved cyclic trigger such as 500 ms.
Sub OnPropertyTrigger()
Static bBlinkState
Dim lAlarmFlag
lAlarmFlag = HMIRuntime.Tags("Tag_Alarm").Read
If lAlarmFlag = 1 Then
bBlinkState = Not bBlinkState
ScreenItems("Rectangle_Alarm").Visible = bBlinkState
Else
bBlinkState = False
ScreenItems("Rectangle_Alarm").Visible = False
End If
End Sub
Easy TestEasy Test 7 — InputBox + MsgBox
Simulation first; then run the original Graphics Designer code in WinCC Runtime.
Dim TestState
TestState = InputBox("Enter test state: 1 = ON / 0 = OFF", "Easy Test 7 — InputBox + MsgBox", "1")
If TestState = "1" Then
MsgBox "Expected Runtime result: object/screen should show the ACTIVE state.", vbInformation, "Graphics Quick Test"
Else
MsgBox "Expected Runtime result: object/screen should show the INACTIVE state.", vbInformation, "Graphics Quick Test"
End IfPrefer the platform’s standard alarm controls and configured flashing dynamics when available. Excessive cyclic VBS can increase Runtime load, and critical alarms must remain visible and accessible. Continue with WinCC VBScript alarm and event handling.
11. Enable controls according to authorization
Configure authorization through WinCC User Administration and use the edition-specific authorization dynamic or API. Do not depend on an unverified numeric permission call.
Function OnPropertyTrigger()
Dim bHasPermission
'Replace with the supported authorization check for the installed WinCC release.
bHasPermission = False
OnPropertyTrigger = bHasPermission
End Function
Easy TestEasy Test 8 — InputBox + MsgBox
A self-contained function test using the same setpoint/actual-value pattern as the SQF project.
Function TestIsOK(ByVal SetValue, ByVal ActualValue)
TestIsOK = (ActualValue >= SetValue)
End Function
Dim SP, PV
SP = CDbl(InputBox("Enter Setpoint", "Easy Test 8 — InputBox + MsgBox", "850"))
PV = CDbl(InputBox("Enter Actual Value", "Easy Test 8 — InputBox + MsgBox", "825"))
MsgBox "Setpoint = " & SP & vbCrLf & _
"Actual = " & PV & vbCrLf & _
"Function Result = " & TestIsOK(SP, PV), _
vbInformation, "Function Quick Test"Test the control with an authorized user, an unauthorized user and no logged-in user. Hiding or disabling a button is not a substitute for PLC-side command authorization. See WinCC operator input validation and command gating for the complete design pattern.
12. Create a reusable project function
Create the project function SetMotorState under Global Script > Project Functions.
Sub SetMotorState(ByVal motorTag, ByVal value)
Dim sTagName, lValue
sTagName = CStr(motorTag)
lValue = CLng(value)
HMIRuntime.Tags(sTagName).Write lValue
HMIRuntime.Trace "Motor tag " & sTagName & _
" set to " & CStr(lValue) & vbCrLf
End Sub
Easy TestEasy Test 9 — InputBox + MsgBox
Self-contained procedure test; no PLC or SQL Server is required.
Sub ShowSQFValue(ByVal NameText, ByVal ValueText)
MsgBox NameText & " = " & ValueText, vbInformation, "Sub Quick Test"
End Sub
Dim TempAct
TempAct = InputBox("Enter Temp_Act", "Easy Test 9 — InputBox + MsgBox", "825.5")
Call ShowSQFValue("Temp_Act", TempAct)Call it from the training button:
Sub OnClick(ByVal Item)
Call SetMotorState("Tag_MotorStart", 1)
End Sub
Easy TestEasy Test 10 — InputBox + MsgBox
Self-contained procedure test; no PLC or SQL Server is required.
Sub ShowSQFValue(ByVal NameText, ByVal ValueText)
MsgBox NameText & " = " & ValueText, vbInformation, "Sub Quick Test"
End Sub
Dim TempAct
TempAct = InputBox("Enter Temp_Act", "Easy Test 10 — InputBox + MsgBox", "825.5")
Call ShowSQFValue("Temp_Act", TempAct)In a production library, validate the supplied tag name against an approved list and return a clear result to the calling action.
13. Observation and verification table
| Program | Object | Tag or input | Expected output | Actual output | Remark |
|---|---|---|---|---|---|
| 1 | Rectangle1 | Tag_Temperature | Color follows value range | ||
| 2 | GroupObject1 | Button event | Object shows and hides | ||
| 3 | Button1 | Tag_MotorStart | Internal tag becomes 1 | ||
| 4 | Rectangle_Level | Tag_TankLevel | Object moves within limits | ||
| 5 | StaticText1 | Tag_PumpStatus | Text follows status | ||
| 6 | Button_Popup | User event | Configured popup opens | ||
| 7 | Rectangle_Alarm | Tag_Alarm | Alarm indication follows flag | ||
| 8 | Button1 | User authorization | Enabled state follows permission | ||
| 9 | Button1 | Tag_MotorStart | Project function writes tag |
14. Troubleshooting WinCC Graphics Designer VBScript
| Runtime symptom | Diagnostic action |
|---|---|
| Object required | Confirm the active picture and exact configured object name. |
| Property does not change | Check for another dynamic or script writing the same property. |
| Tag read returns an unexpected value | Confirm tag type, connection, quality and read sequence. |
| Button action runs twice | Check duplicate event bindings and overlapping cyclic actions. |
| Runtime becomes slow | Replace simple cyclic VBS with native dynamics or reduce trigger frequency. |
| Popup or permission example fails | Use the object model and authorization API documented for the installed edition. |
Hands-on completion test
Practical labPrepare the training picture
Create the five internal tags, seven named objects and a Runtime backup.
Test normal and boundary states
Run every example with its normal values, limits and an invalid input.
Record diagnostics and recovery
Test one missing object or tag in the backed-up project and document the trace result.
Frequently asked questions
Does this VBScript lab work in WinCC Unified?
No. WinCC Unified uses JavaScript. This lab targets the VBS object model used by WinCC Classic/Professional; verify compatibility with the installed product.
Should simple color and visibility changes always use VBScript?
No. Prefer standard WinCC dynamics for simple property changes. Use VBS when the requirement needs coordinated logic, reusable functions or external integration.
Can an HMI script issue a real motor command?
Only through an approved control design. PLC logic must validate operating mode, user authorization, interlocks, permissives and acknowledgement before energizing equipment.
Why can a script work in one picture but fail in another?
Screen context, object names, event signatures and object properties can differ. Confirm the active picture and installed WinCC object model.
SQF Running Project Lab · Blog 10
Use process values to drive graphics
Dim TempSet, TempAct
TempSet = HMIRuntime.Tags("Temp_Set").Read
TempAct = HMIRuntime.Tags("Temp_Act").Read
If TempAct >= TempSet Then
'Set approved graphic status/property to READY
Else
'Set approved graphic status/property to HEATING
End If
Easy TestEasy Test 11 — InputBox + MsgBox
Offline tag simulation: useful before connecting the participant PC to WinCC Runtime.
Dim TestValue, ResultText
ResultText = ""
TestValue = InputBox("Enter simulated value for Temp_Set", "Easy Test 11 — InputBox + MsgBox", "825.5")
ResultText = ResultText & "Temp_Set = " & TestValue & vbCrLf
TestValue = InputBox("Enter simulated value for Temp_Act", "Easy Test 11 — InputBox + MsgBox", "825.5")
ResultText = ResultText & "Temp_Act = " & TestValue & vbCrLf
MsgBox ResultText & vbCrLf & "Now compare these values with the original HMIRuntime .Read example.", vbInformation, "Tag Read Quick Test"