<!-- Softwell WinCC VBScript 20-Part Tutorial · Blog 10 · updated 2026-08-29 --> Control WinCC Graphics with VBScript | Softwell
WinCC Explorer · VBScript · Practical Tutorial

Control WinCC Graphics Designer Objects with VBScript

Use WinCC VBScript to control screen objects, colors, visibility, text, picture windows and navigation through HMIRuntime.

Lab Overview

WinCC VBS Lab 3Estimated time: 75 minutesDifficulty: Intermediate

Prerequisites / What You’ll Need

  • Backed-up WinCC Explorer test project
  • Graphics Designer and Global Script VBS access
  • Internal test tags and Runtime diagnostics

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.

IntermediateWinCC Explorer / Classic WinCCSQF Running Project
Prerequisite

Tag reading, conditions and error diagnostics.

Core concept

Graphics scripts should translate validated process state into clear object properties such as color, visibility, text and position.

SQF practical connection

Animate furnace motor/fan/status objects from SQF process tags and internal states.

Expected competency

Control WinCC screen-object properties through structured scripts without mixing unsafe equipment control into animation code.

Control WinCC Graphics Designer Objects with VBScript — ArchitectureCode-rendered HTML/CSS architecture; no image file required
Process State

Read validated tag/status

Fan_Status
VBScript Logic

Map state to display rule

If ... Then
Screen Object

Resolve named object

ScreenItems("Fan")
Property

Change visual behavior

.BackColor / .Visible
Runtime Display

Operator sees state

Graphics Designer

Complete WinCC VBScript Learning Path

Use Previous/Next for the recommended practical order, or open any topic below as a reference.

WinCC VB Scripting Training →
Easy Testing Method: Every main code example on this page is followed by a copy-ready InputBox + MsgBox test. Use the dialog version first to understand the result, then move to the original WinCC/SQL code. Database writes and equipment commands are previewed or simulated unless the original example is already intended as a lab action.

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.

Compatibility: The 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.
Safety: Use internal tags and a backed-up training project. HMI scripts must not replace PLC safety functions, interlocks, permissives or plant change control.

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 nameData typeDefaultPurpose
1Tag_TemperatureInteger0Simulated temperature
2Tag_TankLevelInteger0Tank level from 0 to 100
3Tag_MotorStartBinary0Motor command for training
4Tag_PumpStatusInteger0Pump state 0, 1 or 2
5Tag_AlarmBinary0Alarm indication flag
  1. Open Tag Management.
  2. Right-click Internal Tags and select New Tag.
  3. Enter the exact tag name and select the specified data type.
  4. Save the tag and repeat for the remaining entries.
  5. 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 nameObject typeLab purpose
Rectangle1RectangleTemperature-state color
GroupObject1Group or graphic objectShow/hide demonstration
Button1ButtonOperator event and tag write
Rectangle_LevelRectangleTank-level movement
StaticText1Static TextDynamic pump-state text
Rectangle_AlarmRectangleAlarm indication
Button_PopupButtonPopup 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 If

Test: 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 If

Test 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 If

Confirm 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 If

Test 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 If

The 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 If

Prefer 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

ProgramObjectTag or inputExpected outputActual outputRemark
1Rectangle1Tag_TemperatureColor follows value range
2GroupObject1Button eventObject shows and hides
3Button1Tag_MotorStartInternal tag becomes 1
4Rectangle_LevelTag_TankLevelObject moves within limits
5StaticText1Tag_PumpStatusText follows status
6Button_PopupUser eventConfigured popup opens
7Rectangle_AlarmTag_AlarmAlarm indication follows flag
8Button1User authorizationEnabled state follows permission
9Button1Tag_MotorStartProject function writes tag

14. Troubleshooting WinCC Graphics Designer VBScript

Runtime symptomDiagnostic action
Object requiredConfirm the active picture and exact configured object name.
Property does not changeCheck for another dynamic or script writing the same property.
Tag read returns an unexpected valueConfirm tag type, connection, quality and read sequence.
Button action runs twiceCheck duplicate event bindings and overlapping cyclic actions.
Runtime becomes slowReplace simple cyclic VBS with native dynamics or reduce trigger frequency.
Popup or permission example failsUse the object model and authorization API documented for the installed edition.

Hands-on completion test

Practical lab
1

Prepare the training picture

Create the five internal tags, seven named objects and a Runtime backup.

Every script reference resolves to an existing tag or object.
2

Test normal and boundary states

Run every example with its normal values, limits and an invalid input.

Results match the observation table without stale or uncontrolled states.
3

Record diagnostics and recovery

Test one missing object or tag in the backed-up project and document the trace result.

The fault can be identified and the project restored without affecting PLC control.

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.

Get the WinCC VB Scripting syllabus

Share your details and a Softwell advisor will contact you with practical training options.

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"
Graphics should visualize process state; PLC logic remains the source of machine protection and interlocks.

Build reliable WinCC VBScript projects

Join practical online, classroom or corporate training.

Request Course Details
WinCC VBScript Learning Path 3 of 10

Runtime screen-object control: engineering guide

Control visibility, color, text, picture windows and navigation while keeping screen behavior understandable to operators and maintenance engineers.

Implementation and commissioning checklist

Practical completion outcome

A graphics action that changes only the intended object properties and fails without disrupting navigation.

Safety boundary: Validate scripts on a backed-up WinCC training or staging project. PLC safety functions, permissives and interlocks must remain independent of HMI scripting.

Verified learning pathway

Discuss WinCC VB Scripting Training

Explore practical WinCC VBS, SCADA, SQL reporting and industrial automation training options.

Content reviewed: 4 August 2026

☎ Call WhatsApp ✉ Email Enquire Now