Read and Write WinCC Tags with VBScript: HMIRuntime Guide
This lab targets wincc vbscript read write tags with copy-ready examples, expected results and diagnostic guidance.
1. Understand the WinCC Tag Object
HMIRuntime.Tags("TagName") returns a WinCC Runtime tag object. The object exposes the process value plus diagnostic properties such as QualityCode, TimeStamp, LastError and ErrorDescription. Keep a reference with Set when several properties are needed.
Dim processTag
Set processTag = HMIRuntime.Tags("Demo_Temperature")
processTag.Read
HMIRuntime.Trace "Value=" & CStr(processTag.Value)
Set processTag = Nothing
2. Read Value, Quality and Timestamp Together
Dim processTag
Set processTag = HMIRuntime.Tags("Demo_Temperature")
processTag.Read
HMIRuntime.Trace "Value=" & CStr(processTag.Value) & _
", Quality=" & CStr(processTag.QualityCode) & _
", Time=" & CStr(processTag.TimeStamp)
If processTag.LastError <> 0 Then
HMIRuntime.Trace "Tag error: " & processTag.ErrorDescription
End If
Set processTag = Nothing3. Validate a Value Before Writing
Dim setpointTag
Dim requestedSetpoint
requestedSetpoint = 650
If IsNumeric(requestedSetpoint) Then
If CDbl(requestedSetpoint) >= 0 And CDbl(requestedSetpoint) <= 900 Then
Set setpointTag = HMIRuntime.Tags("Demo_TempSetpoint")
setpointTag.Write CDbl(requestedSetpoint)
Set setpointTag = Nothing
Else
HMIRuntime.Trace "Rejected: setpoint outside 0..900"
End If
End IfUse User Administration and PLC-side limits in addition to the script. The HMI validates the request; the PLC remains responsible for permissives, modes and equipment protection.
4. Read Multiple Tags Clearly
Create one object per tag, use descriptive names and release every reference. Avoid building tag names from unchecked operator text. Literal tag names are also easier for WinCC cross-reference tools to identify.
5. Tag Read/Write Troubleshooting
| Symptom | Check |
|---|---|
| Value is empty | Tag name, connection, data type and whether Read was called |
| Quality is bad | PLC state, channel diagnostics, address and network route |
| Write returns but process does not change | Authorization, PLC mode, command handshake and interlocks |
Hands-On Verification Lab
Hands-onPrepare a controlled test
Create only the internal tags, folders or disposable database rows required by this tutorial.
Run the smallest example
Execute one operation and inspect WinCC diagnostics before expanding the script.
Test a failure path
Use a safe backup copy to test an invalid tag, path or disposable input.
Frequently Asked Questions
Should this WinCC VBScript be tested in production?
No. Use a backed-up training or staging project and follow the plant change-control process.
Which WinCC versions does the example target?
The examples target classic WinCC Explorer V7.x/V8.x. Verify object properties, action signatures and providers in the installed WinCC help.
How should Runtime failures be diagnosed?
Use scoped Err checks, WinCC object diagnostics and HMIRuntime.Trace while recording the exact station, trigger, tag and Runtime identity.
