WinCC Explorer · VBScript · Object Practice

WinCC Explorer VBScript Object-Based Practice Lab Manual

Six worked exercises covering buttons, lamps, valves, screen navigation and dynamic HMI objects.

Buttons Lamps Valves Dynamic Objects

Trainer Reference Document

Brand: Softwell AutomationDivision: Industrial Automation TrainingPlatform: WinCC ExplorerFormat: 6 worked exercises

Manual Scope

This blog preserves the complete contents of the attached Object-Based Practice Lab Manual and presents them in the established Softwell blog layout.

Learning Foundation: Integrated HMI Object Practice

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.

Project PracticeWinCC Explorer / Classic WinCCSQF Running Project
Prerequisite

Complete core syntax, tags, conditions, loops, functions, graphics and diagnostics first.

Core concept

Move from isolated syntax exercises to object-event labs where buttons, I/O fields, bars, text, popups and graphics call small maintainable scripts.

SQF practical connection

Build SQF object interactions that read status, validate commands, update graphics and open contextual views.

Expected competency

Connect WinCC screen-object events to reusable VBScript logic and verify each object behavior in Runtime.

WinCC Explorer VBScript Object-Based Practice Lab Manual — ArchitectureCode-rendered HTML/CSS architecture; no image file required
Screen Object

Button / field / lamp / bar

Graphics Designer
Object Event

Click/change/runtime event

OnClick
VBScript

Call focused procedure

Sub ...
Tags / Properties

Read/write or animate

HMIRuntime / ScreenItems
Runtime Test

Verify expected object behavior

Practical lab

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 →
Repeatable workflow

Create the supporting Internal Tags, place and name the graphic object, open the correct Properties/Event node, attach the VBScript action or dynamic, paste the code, and test in Runtime.

How to Use This Manual

Each of the six exercises below follows the same repeatable workflow used throughout Softwell's WinCC Explorer training: create the supporting Internal Tags, place and name the graphic object, open the correct Properties/Event node, attach a VBScript action or dynamic, paste the code, and test in Runtime.

Object names given in each exercise match the tag and object references used inside the VBScript code, so trainees can copy the code directly without editing variable or object names.

Exercise Overview

#ExerciseObject NameEvent / Property Used
1Motor Start/Stop with InterlockMotor_Start_ButtonMouse Click
2Indicator Lamp Color Change (Dynamic Property)Motor_Status_LampDynamic (VBScript)
3Blinking Alarm LampAlarm_Blink_LampVBScript, Cyclic Trigger 500 ms
4Screen Navigation Button with Login CheckNavButton_TankMouse Click
5Valve Toggle with Confirmation PopupValve_ObjectMouse Click
6Tank Fill Bar Level AnimationTank_FillBarDynamic (VBScript)

Exercise 1: Motor Start/Stop with Interlock

Object Type: Button (Standard Object → Button)

Object Name: Motor_Start_Button

Event / Property Path: Properties → Events → Mouse → Mouse Click

Step 1 — Create Internal Tags

Tag NameData TypePurpose
Motor_FaultBinary TagIndicates active fault condition (1 = fault)
Motor_RunningBinary TagFeedback showing motor is currently running
Motor_Cmd_StartBinary TagOutput command sent to PLC to start the motor

Step 2 — Create Object & Attach Script

StepActionDetails
1Open Tag ManagementIn WinCC Explorer, expand Tag Management → right-click the relevant driver connection (or Internal Tags) → New Tag.
2Create Internal TagName: "Motor_Fault" | Data Type: Binary Tag. Click OK to save.
3Create Internal TagName: "Motor_Running" | Data Type: Binary Tag. Click OK to save.
4Create Internal TagName: "Motor_Cmd_Start" | Data Type: Binary Tag. Click OK to save.
5Open Graphics DesignerOpen the target screen (.pdl) in Graphics Designer where the object will be placed.
6Insert ObjectFrom the Object Palette, drag a Button (Standard Object → Button) onto the screen.
7Rename ObjectRight-click the object → Properties → General tab (or Object Name field) → set Object Name to "Motor_Start_Button".
8Open Properties/EventsIn the Object Properties dialog, navigate to: Properties → Events → Mouse → Mouse Click.
9Choose VBSRight-click the selected Event/Property field → "Dynamic" or "Action" → select VBScript as the action/dynamic language (not C or Global Script, unless noted).
10Paste CodeIn the VBS editor that opens, paste the "OnClick_MotorStart" code block (see below), then click Compile / Check Syntax.
11Set TriggerN/A — direct Mouse Click action, no cyclic trigger needed
12Save & ActivateSave the screen (Ctrl+S), close Graphics Designer, then start WinCC Runtime to test the object's behavior live.

Step 3 — VBScript Code (OnClick_MotorStart)

Sub OnClick_MotorStart()
Dim faultStatus, motorRunning
faultStatus   = HMIRuntime.Tags("Motor_Fault").Read()
motorRunning  = HMIRuntime.Tags("Motor_Running").Read()
If faultStatus = 1 Then
HMIRuntime.Trace "Cannot start: Motor fault active" & vbCrLf
MsgBox "Motor Fault Active! Reset before starting.", _
vbCritical, "Interlock"
ElseIf motorRunning = 1 Then
HMIRuntime.Trace "Motor already running" & vbCrLf
Else
HMIRuntime.Tags("Motor_Cmd_Start").Write(1)
HMIRuntime.Trace "Motor Start command issued" & vbCrLf
End If
End Sub

Exercise 2: Indicator Lamp Color Change (Dynamic Property)

Object Type: Circle / Rectangle (Standard Object → Circle)

Object Name: Motor_Status_Lamp

Event / Property Path: Properties → Colors → Background Color → right-click → Dynamic (VBScript)

Step 1 — Create Internal Tags

Tag NameData TypePurpose
Motor_RunningBinary Tag1 = motor running (drives lamp green)
Motor_FaultBinary Tag1 = fault present (drives lamp red, highest priority)

Step 2 — Create Object & Attach Script

StepActionDetails
1Open Tag ManagementIn WinCC Explorer, expand Tag Management → right-click the relevant driver connection (or Internal Tags) → New Tag.
2Create Internal TagName: "Motor_Running" | Data Type: Binary Tag. Click OK to save.
3Create Internal TagName: "Motor_Fault" | Data Type: Binary Tag. Click OK to save.
4Open Graphics DesignerOpen the target screen (.pdl) in Graphics Designer where the object will be placed.
5Insert ObjectFrom the Object Palette, drag a Circle / Rectangle (Standard Object → Circle) onto the screen.
6Rename ObjectRight-click the object → Properties → General tab (or Object Name field) → set Object Name to "Motor_Status_Lamp".
7Open Properties/EventsIn the Object Properties dialog, navigate to: Properties → Colors → Background Color → right-click → Dynamic (VBScript).
8Choose VBSRight-click the selected Event/Property field → "Dynamic" or "Action" → select VBScript as the action/dynamic language (not C or Global Script, unless noted).
9Paste CodeIn the VBS editor that opens, paste the "Dynamic Background Color" code block (see below), then click Compile / Check Syntax.
10Set TriggerTrigger: Tag change on Motor_Running / Motor_Fault (or cyclic 250 ms)
11Save & ActivateSave the screen (Ctrl+S), close Graphics Designer, then start WinCC Runtime to test the object's behavior live.

Step 3 — VBScript Code (Dynamic Background Color)

Dim runStatus, faultStatus
runStatus   = HMIRuntime.Tags("Motor_Running").Read()
faultStatus = HMIRuntime.Tags("Motor_Fault").Read()
Select Case True
Case faultStatus = 1
Me.BackColor = RGB(255, 0, 0)      ' Red - Fault
Case runStatus = 1
Me.BackColor = RGB(0, 255, 0)      ' Green - Running
Case Else
Me.BackColor = RGB(192, 192, 192)  ' Gray - Stopped/Idle
End Select

Exercise 3: Blinking Alarm Lamp

Object Type: Circle (Standard Object → Circle), driven by a separate Global Script action

Object Name: Alarm_Blink_Lamp

Event / Property Path: Global Script → Actions → New Action → VBScript, Cyclic Trigger 500 ms

Step 1 — Create Internal Tags

Tag NameData TypePurpose
Alarm_ActiveBinary Tag1 = an active alarm exists
Lamp_Blink_OutBinary TagToggled output tag; bind this to the lamp's Background Color dynamic (like Lab 2)

Step 2 — Create Object & Attach Script

StepActionDetails
1Open Tag ManagementIn WinCC Explorer, expand Tag Management → right-click the relevant driver connection (or Internal Tags) → New Tag.
2Create Internal TagName: "Alarm_Active" | Data Type: Binary Tag. Click OK to save.
3Create Internal TagName: "Lamp_Blink_Out" | Data Type: Binary Tag. Click OK to save.
4Open Graphics DesignerOpen the target screen (.pdl) in Graphics Designer where the object will be placed.
5Insert ObjectFrom the Object Palette, drag a Circle (Standard Object → Circle), driven by a separate Global Script action onto the screen.
6Rename ObjectRight-click the object → Properties → General tab (or Object Name field) → set Object Name to "Alarm_Blink_Lamp".
7Open Properties/EventsIn the Object Properties dialog, navigate to: Global Script → Actions → New Action → VBScript, Cyclic Trigger 500 ms.
8Choose VBSRight-click the selected Event/Property field → "Dynamic" or "Action" → select VBScript as the action/dynamic language (not C or Global Script, unless noted).
9Paste CodeIn the VBS editor that opens, paste the "BlinkAlarmLamp" code block (see below), then click Compile / Check Syntax.
10Set TriggerTrigger: Standard Cycle → 500 ms (set in the Action's Trigger tab)
11Save & ActivateSave the screen (Ctrl+S), close Graphics Designer, then start WinCC Runtime to test the object's behavior live.

Step 3 — VBScript Code (BlinkAlarmLamp)

Sub BlinkAlarmLamp()
Static blinkState
If HMIRuntime.Tags("Alarm_Active").Read() = 1 Then
blinkState = Not blinkState
HMIRuntime.Tags("Lamp_Blink_Out").Write(CInt(blinkState))
Else
HMIRuntime.Tags("Lamp_Blink_Out").Write(0)
End If
End Sub
Trainer Note

Link Alarm_Blink_Lamp's Background Color dynamic to Lamp_Blink_Out using the same Select Case pattern as Lab 2 (1 = red/on, 0 = gray/off).

Exercise 4: Screen Navigation Button with Login Check

Object Type: Button (Standard Object → Button)

Object Name: NavButton_Tank

Event / Property Path: Properties → Events → Mouse → Mouse Click

Step 1 — Create Internal Tags

Tag NameData TypePurpose
@CurrentUserSystem Tag (built-in)Holds the currently logged-in user name; no manual creation needed

Step 2 — Create Object & Attach Script

StepActionDetails
1Open Tag ManagementIn WinCC Explorer, expand Tag Management → right-click the relevant driver connection (or Internal Tags) → New Tag.
2Create Internal TagName: "@CurrentUser" | Data Type: System Tag (built-in). Click OK to save.
3Open Graphics DesignerOpen the target screen (.pdl) in Graphics Designer where the object will be placed.
4Insert ObjectFrom the Object Palette, drag a Button (Standard Object → Button) onto the screen.
5Rename ObjectRight-click the object → Properties → General tab (or Object Name field) → set Object Name to "NavButton_Tank".
6Open Properties/EventsIn the Object Properties dialog, navigate to: Properties → Events → Mouse → Mouse Click.
7Choose VBSRight-click the selected Event/Property field → "Dynamic" or "Action" → select VBScript as the action/dynamic language (not C or Global Script, unless noted).
8Paste CodeIn the VBS editor that opens, paste the "OnClick_OpenTankScreen" code block (see below), then click Compile / Check Syntax.
9Set TriggerN/A — direct Mouse Click action
10Save & ActivateSave the screen (Ctrl+S), close Graphics Designer, then start WinCC Runtime to test the object's behavior live.

Step 3 — VBScript Code (OnClick_OpenTankScreen)

Sub OnClick_OpenTankScreen()
Dim currentUser
currentUser = HMIRuntime.Tags("@CurrentUser").Read()
If currentUser = "" Then
MsgBox "Please log in to access this screen.", vbExclamation, "Access Denied"
Else
HMIRuntime.BaseScreenName = "Tank_Overview.pdl"
HMIRuntime.Trace "Navigated to Tank_Overview by " & currentUser & vbCrLf
End If
End Sub
Trainer Note

Ensure a screen named Tank_Overview.pdl exists in Graphics Designer before testing, or substitute your own target screen name.

Exercise 5: Valve Toggle with Confirmation Popup

Object Type: Circle / Symbol Object (Standard Object → Circle, styled as a valve symbol)

Object Name: Valve_Object

Event / Property Path: Properties → Events → Mouse → Mouse Click

Step 1 — Create Internal Tags

Tag NameData TypePurpose
Valve1_StatusBinary Tag0 = closed, 1 = open — current valve feedback
Valve1_CmdBinary TagCommand tag written to the PLC to open/close the valve

Step 2 — Create Object & Attach Script

StepActionDetails
1Open Tag ManagementIn WinCC Explorer, expand Tag Management → right-click the relevant driver connection (or Internal Tags) → New Tag.
2Create Internal TagName: "Valve1_Status" | Data Type: Binary Tag. Click OK to save.
3Create Internal TagName: "Valve1_Cmd" | Data Type: Binary Tag. Click OK to save.
4Open Graphics DesignerOpen the target screen (.pdl) in Graphics Designer where the object will be placed.
5Insert ObjectFrom the Object Palette, drag a Circle / Symbol Object (Standard Object → Circle, styled as a valve symbol) onto the screen.
6Rename ObjectRight-click the object → Properties → General tab (or Object Name field) → set Object Name to "Valve_Object".
7Open Properties/EventsIn the Object Properties dialog, navigate to: Properties → Events → Mouse → Mouse Click.
8Choose VBSRight-click the selected Event/Property field → "Dynamic" or "Action" → select VBScript as the action/dynamic language (not C or Global Script, unless noted).
9Paste CodeIn the VBS editor that opens, paste the "OnClick_ToggleValve" code block (see below), then click Compile / Check Syntax.
10Set TriggerN/A — direct Mouse Click action
11Save & ActivateSave the screen (Ctrl+S), close Graphics Designer, then start WinCC Runtime to test the object's behavior live.

Step 3 — VBScript Code (OnClick_ToggleValve)

Sub OnClick_ToggleValve()
Dim valveState, response
valveState = HMIRuntime.Tags("Valve1_Status").Read()
response = MsgBox("Confirm valve " & IIf(valveState = 1, "CLOSE", "OPEN") & "?", _
vbYesNo + vbQuestion, "Valve Confirmation")
If response = vbYes Then
Select Case valveState
Case 0
HMIRuntime.Tags("Valve1_Cmd").Write(1)
Case 1
HMIRuntime.Tags("Valve1_Cmd").Write(0)
Case Else
HMIRuntime.Trace "Valve1_Status: undefined state" & vbCrLf
End Select
End If
End Sub
Function IIf(cond, tPart, fPart)
If cond Then IIf = tPart Else IIf = fPart
End Function
Trainer Note

VBS has no built-in IIf (unlike VBA) — the helper function must be included in the same action, or in a Global Script project function.

Exercise 6: Tank Fill Bar Level Animation

Object Type: Rectangle (Standard Object → Rectangle, styled as a vertical fill bar)

Object Name: Tank_FillBar

Event / Property Path: Properties → Geometry → Height → right-click → Dynamic (VBScript)

Step 1 — Create Internal Tags

Tag NameData TypePurpose
Tank_LevelAnalog Tag (0–100%)Current tank fill percentage from the PLC

Step 2 — Create Object & Attach Script

StepActionDetails
1Open Tag ManagementIn WinCC Explorer, expand Tag Management → right-click the relevant driver connection (or Internal Tags) → New Tag.
2Create Internal TagName: "Tank_Level" | Data Type: Analog Tag (0–100%). Click OK to save.
3Open Graphics DesignerOpen the target screen (.pdl) in Graphics Designer where the object will be placed.
4Insert ObjectFrom the Object Palette, drag a Rectangle (Standard Object → Rectangle, styled as a vertical fill bar) onto the screen.
5Rename ObjectRight-click the object → Properties → General tab (or Object Name field) → set Object Name to "Tank_FillBar".
6Open Properties/EventsIn the Object Properties dialog, navigate to: Properties → Geometry → Height → right-click → Dynamic (VBScript).
7Choose VBSRight-click the selected Event/Property field → "Dynamic" or "Action" → select VBScript as the action/dynamic language (not C or Global Script, unless noted).
8Paste CodeIn the VBS editor that opens, paste the "Dynamic Height" code block (see below), then click Compile / Check Syntax.
9Set TriggerTrigger: Tag change on Tank_Level (or cyclic 250 ms)
10Save & ActivateSave the screen (Ctrl+S), close Graphics Designer, then start WinCC Runtime to test the object's behavior live.

Step 3 — VBScript Code (Dynamic Height)

Dim level, maxHeight
level = HMIRuntime.Tags("Tank_Level").Read()
maxHeight = 200   ' pixels, matches full-tank graphic height
If level < 0 Then level = 0
If level > 100 Then level = 100
Me.Height = (level / 100) * maxHeight
Trainer Note

Anchor the rectangle's bottom edge (not top) in the object's Geometry settings so the bar fills upward as Height increases.

Lab Completion Checklist

  1. All object and tag names match the VBScript references exactly.
  2. Each script passes Compile / Check Syntax.
  3. Dynamic properties use the correct tag-change or cyclic trigger.
  4. Runtime tests cover normal, fault and invalid-input conditions.
  5. Trainer notes are reviewed before commissioning each exercise.

Get WinCC Explorer VBScript Training Details

Share your details and a Softwell advisor will contact you with practical WinCC, PLC and SCADA training options.

Build practical WinCC VBScript skills

Learn object events, tag access, graphics dynamics and reusable runtime automation.

Request Course Details
Verified learning pathway

Discuss WinCC Explorer VBScript Object Training

Explore practical SCL, PLC and SCADA integration training options.

Content reviewed: 30 August 2026

☎ Call WhatsApp ✉ Email Enquire Now