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.
Complete core syntax, tags, conditions, loops, functions, graphics and diagnostics first.
Move from isolated syntax exercises to object-event labs where buttons, I/O fields, bars, text, popups and graphics call small maintainable scripts.
Build SQF object interactions that read status, validate commands, update graphics and open contextual views.
Connect WinCC screen-object events to reusable VBScript logic and verify each object behavior in Runtime.
Button / field / lamp / bar
Click/change/runtime event
Call focused procedure
Read/write or animate
Verify expected object behavior
Complete WinCC VBScript Learning Path
Use Previous/Next for the recommended practical order, or open any topic below as a reference.
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
| # | Exercise | Object Name | Event / Property Used |
|---|---|---|---|
| 1 | Motor Start/Stop with Interlock | Motor_Start_Button | Mouse Click |
| 2 | Indicator Lamp Color Change (Dynamic Property) | Motor_Status_Lamp | Dynamic (VBScript) |
| 3 | Blinking Alarm Lamp | Alarm_Blink_Lamp | VBScript, Cyclic Trigger 500 ms |
| 4 | Screen Navigation Button with Login Check | NavButton_Tank | Mouse Click |
| 5 | Valve Toggle with Confirmation Popup | Valve_Object | Mouse Click |
| 6 | Tank Fill Bar Level Animation | Tank_FillBar | Dynamic (VBScript) |
Exercise 1: Motor Start/Stop with Interlock
Step 1 — Create Internal Tags
| Tag Name | Data Type | Purpose |
|---|---|---|
| Motor_Fault | Binary Tag | Indicates active fault condition (1 = fault) |
| Motor_Running | Binary Tag | Feedback showing motor is currently running |
| Motor_Cmd_Start | Binary Tag | Output command sent to PLC to start the motor |
Step 2 — Create Object & Attach Script
| Step | Action | Details |
|---|---|---|
| 1 | Open Tag Management | In WinCC Explorer, expand Tag Management → right-click the relevant driver connection (or Internal Tags) → New Tag. |
| 2 | Create Internal Tag | Name: "Motor_Fault" | Data Type: Binary Tag. Click OK to save. |
| 3 | Create Internal Tag | Name: "Motor_Running" | Data Type: Binary Tag. Click OK to save. |
| 4 | Create Internal Tag | Name: "Motor_Cmd_Start" | Data Type: Binary Tag. Click OK to save. |
| 5 | Open Graphics Designer | Open the target screen (.pdl) in Graphics Designer where the object will be placed. |
| 6 | Insert Object | From the Object Palette, drag a Button (Standard Object → Button) onto the screen. |
| 7 | Rename Object | Right-click the object → Properties → General tab (or Object Name field) → set Object Name to "Motor_Start_Button". |
| 8 | Open Properties/Events | In the Object Properties dialog, navigate to: Properties → Events → Mouse → Mouse Click. |
| 9 | Choose VBS | Right-click the selected Event/Property field → "Dynamic" or "Action" → select VBScript as the action/dynamic language (not C or Global Script, unless noted). |
| 10 | Paste Code | In the VBS editor that opens, paste the "OnClick_MotorStart" code block (see below), then click Compile / Check Syntax. |
| 11 | Set Trigger | N/A — direct Mouse Click action, no cyclic trigger needed |
| 12 | Save & Activate | Save 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 SubExercise 2: Indicator Lamp Color Change (Dynamic Property)
Step 1 — Create Internal Tags
| Tag Name | Data Type | Purpose |
|---|---|---|
| Motor_Running | Binary Tag | 1 = motor running (drives lamp green) |
| Motor_Fault | Binary Tag | 1 = fault present (drives lamp red, highest priority) |
Step 2 — Create Object & Attach Script
| Step | Action | Details |
|---|---|---|
| 1 | Open Tag Management | In WinCC Explorer, expand Tag Management → right-click the relevant driver connection (or Internal Tags) → New Tag. |
| 2 | Create Internal Tag | Name: "Motor_Running" | Data Type: Binary Tag. Click OK to save. |
| 3 | Create Internal Tag | Name: "Motor_Fault" | Data Type: Binary Tag. Click OK to save. |
| 4 | Open Graphics Designer | Open the target screen (.pdl) in Graphics Designer where the object will be placed. |
| 5 | Insert Object | From the Object Palette, drag a Circle / Rectangle (Standard Object → Circle) onto the screen. |
| 6 | Rename Object | Right-click the object → Properties → General tab (or Object Name field) → set Object Name to "Motor_Status_Lamp". |
| 7 | Open Properties/Events | In the Object Properties dialog, navigate to: Properties → Colors → Background Color → right-click → Dynamic (VBScript). |
| 8 | Choose VBS | Right-click the selected Event/Property field → "Dynamic" or "Action" → select VBScript as the action/dynamic language (not C or Global Script, unless noted). |
| 9 | Paste Code | In the VBS editor that opens, paste the "Dynamic Background Color" code block (see below), then click Compile / Check Syntax. |
| 10 | Set Trigger | Trigger: Tag change on Motor_Running / Motor_Fault (or cyclic 250 ms) |
| 11 | Save & Activate | Save 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 SelectExercise 3: Blinking Alarm Lamp
Step 1 — Create Internal Tags
| Tag Name | Data Type | Purpose |
|---|---|---|
| Alarm_Active | Binary Tag | 1 = an active alarm exists |
| Lamp_Blink_Out | Binary Tag | Toggled output tag; bind this to the lamp's Background Color dynamic (like Lab 2) |
Step 2 — Create Object & Attach Script
| Step | Action | Details |
|---|---|---|
| 1 | Open Tag Management | In WinCC Explorer, expand Tag Management → right-click the relevant driver connection (or Internal Tags) → New Tag. |
| 2 | Create Internal Tag | Name: "Alarm_Active" | Data Type: Binary Tag. Click OK to save. |
| 3 | Create Internal Tag | Name: "Lamp_Blink_Out" | Data Type: Binary Tag. Click OK to save. |
| 4 | Open Graphics Designer | Open the target screen (.pdl) in Graphics Designer where the object will be placed. |
| 5 | Insert Object | From the Object Palette, drag a Circle (Standard Object → Circle), driven by a separate Global Script action onto the screen. |
| 6 | Rename Object | Right-click the object → Properties → General tab (or Object Name field) → set Object Name to "Alarm_Blink_Lamp". |
| 7 | Open Properties/Events | In the Object Properties dialog, navigate to: Global Script → Actions → New Action → VBScript, Cyclic Trigger 500 ms. |
| 8 | Choose VBS | Right-click the selected Event/Property field → "Dynamic" or "Action" → select VBScript as the action/dynamic language (not C or Global Script, unless noted). |
| 9 | Paste Code | In the VBS editor that opens, paste the "BlinkAlarmLamp" code block (see below), then click Compile / Check Syntax. |
| 10 | Set Trigger | Trigger: Standard Cycle → 500 ms (set in the Action's Trigger tab) |
| 11 | Save & Activate | Save 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 SubLink 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
Step 1 — Create Internal Tags
| Tag Name | Data Type | Purpose |
|---|---|---|
| @CurrentUser | System Tag (built-in) | Holds the currently logged-in user name; no manual creation needed |
Step 2 — Create Object & Attach Script
| Step | Action | Details |
|---|---|---|
| 1 | Open Tag Management | In WinCC Explorer, expand Tag Management → right-click the relevant driver connection (or Internal Tags) → New Tag. |
| 2 | Create Internal Tag | Name: "@CurrentUser" | Data Type: System Tag (built-in). Click OK to save. |
| 3 | Open Graphics Designer | Open the target screen (.pdl) in Graphics Designer where the object will be placed. |
| 4 | Insert Object | From the Object Palette, drag a Button (Standard Object → Button) onto the screen. |
| 5 | Rename Object | Right-click the object → Properties → General tab (or Object Name field) → set Object Name to "NavButton_Tank". |
| 6 | Open Properties/Events | In the Object Properties dialog, navigate to: Properties → Events → Mouse → Mouse Click. |
| 7 | Choose VBS | Right-click the selected Event/Property field → "Dynamic" or "Action" → select VBScript as the action/dynamic language (not C or Global Script, unless noted). |
| 8 | Paste Code | In the VBS editor that opens, paste the "OnClick_OpenTankScreen" code block (see below), then click Compile / Check Syntax. |
| 9 | Set Trigger | N/A — direct Mouse Click action |
| 10 | Save & Activate | Save 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 SubEnsure 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
Step 1 — Create Internal Tags
| Tag Name | Data Type | Purpose |
|---|---|---|
| Valve1_Status | Binary Tag | 0 = closed, 1 = open — current valve feedback |
| Valve1_Cmd | Binary Tag | Command tag written to the PLC to open/close the valve |
Step 2 — Create Object & Attach Script
| Step | Action | Details |
|---|---|---|
| 1 | Open Tag Management | In WinCC Explorer, expand Tag Management → right-click the relevant driver connection (or Internal Tags) → New Tag. |
| 2 | Create Internal Tag | Name: "Valve1_Status" | Data Type: Binary Tag. Click OK to save. |
| 3 | Create Internal Tag | Name: "Valve1_Cmd" | Data Type: Binary Tag. Click OK to save. |
| 4 | Open Graphics Designer | Open the target screen (.pdl) in Graphics Designer where the object will be placed. |
| 5 | Insert Object | From the Object Palette, drag a Circle / Symbol Object (Standard Object → Circle, styled as a valve symbol) onto the screen. |
| 6 | Rename Object | Right-click the object → Properties → General tab (or Object Name field) → set Object Name to "Valve_Object". |
| 7 | Open Properties/Events | In the Object Properties dialog, navigate to: Properties → Events → Mouse → Mouse Click. |
| 8 | Choose VBS | Right-click the selected Event/Property field → "Dynamic" or "Action" → select VBScript as the action/dynamic language (not C or Global Script, unless noted). |
| 9 | Paste Code | In the VBS editor that opens, paste the "OnClick_ToggleValve" code block (see below), then click Compile / Check Syntax. |
| 10 | Set Trigger | N/A — direct Mouse Click action |
| 11 | Save & Activate | Save 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 FunctionVBS 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
Step 1 — Create Internal Tags
| Tag Name | Data Type | Purpose |
|---|---|---|
| Tank_Level | Analog Tag (0–100%) | Current tank fill percentage from the PLC |
Step 2 — Create Object & Attach Script
| Step | Action | Details |
|---|---|---|
| 1 | Open Tag Management | In WinCC Explorer, expand Tag Management → right-click the relevant driver connection (or Internal Tags) → New Tag. |
| 2 | Create Internal Tag | Name: "Tank_Level" | Data Type: Analog Tag (0–100%). Click OK to save. |
| 3 | Open Graphics Designer | Open the target screen (.pdl) in Graphics Designer where the object will be placed. |
| 4 | Insert Object | From the Object Palette, drag a Rectangle (Standard Object → Rectangle, styled as a vertical fill bar) onto the screen. |
| 5 | Rename Object | Right-click the object → Properties → General tab (or Object Name field) → set Object Name to "Tank_FillBar". |
| 6 | Open Properties/Events | In the Object Properties dialog, navigate to: Properties → Geometry → Height → right-click → Dynamic (VBScript). |
| 7 | Choose VBS | Right-click the selected Event/Property field → "Dynamic" or "Action" → select VBScript as the action/dynamic language (not C or Global Script, unless noted). |
| 8 | Paste Code | In the VBS editor that opens, paste the "Dynamic Height" code block (see below), then click Compile / Check Syntax. |
| 9 | Set Trigger | Trigger: Tag change on Tank_Level (or cyclic 250 ms) |
| 10 | Save & Activate | Save 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) * maxHeightAnchor the rectangle's bottom edge (not top) in the object's Geometry settings so the bar fills upward as Height increases.
Lab Completion Checklist
- All object and tag names match the VBScript references exactly.
- Each script passes Compile / Check Syntax.
- Dynamic properties use the correct tag-change or cyclic trigger.
- Runtime tests cover normal, fault and invalid-input conditions.
- Trainer notes are reviewed before commissioning each exercise.
