Learning Foundation: WinCC Runtime Tag Access
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.
VBScript variables, conversion, conditions and reusable functions. Test first with internal tags.
HMIRuntime.Tags is the bridge between VBScript and configured WinCC tags. Read, validate, act, then write only approved command/setpoint values.
Read SQF temperatures and statuses; write validated setpoints or internal command requests.
Use HMIRuntime.Tags().Read and .Write with conversion, validation and diagnostic checks.
Configured WinCC data point
Resolve through Runtime
Acquire current value
Apply engineering rules
Send approved result
Complete WinCC VBScript Learning Path
Use Previous/Next for the recommended practical order, or open any topic below as a reference.
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
Easy TestEasy Test 1 — InputBox + MsgBox
Offline tag simulation: useful before connecting the participant PC to WinCC Runtime.
Dim TestValue, ResultText
ResultText = ""
TestValue = InputBox("Enter simulated value for Demo_Temperature", "Easy Test 1 — InputBox + MsgBox", "825.5")
ResultText = ResultText & "Demo_Temperature = " & TestValue & vbCrLf
MsgBox ResultText & vbCrLf & "Now compare these values with the original HMIRuntime .Read example.", vbInformation, "Tag Read Quick Test"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 = Nothing
Easy TestEasy Test 2 — InputBox + MsgBox
Offline tag simulation: useful before connecting the participant PC to WinCC Runtime.
Dim TestValue, ResultText
ResultText = ""
TestValue = InputBox("Enter simulated value for Demo_Temperature", "Easy Test 2 — InputBox + MsgBox", "825.5")
ResultText = ResultText & "Demo_Temperature = " & TestValue & vbCrLf
MsgBox ResultText & vbCrLf & "Now compare these values with the original HMIRuntime .Read example.", vbInformation, "Tag Read Quick Test"3. 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 If
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: Demo_TempSetpoint", "Easy Test 3 — InputBox + MsgBox", "1")
If TestValue = "" Then
MsgBox "Test cancelled.", vbInformation, "Tag Write Quick Test"
Else
MsgBox "SIMULATION ONLY" & vbCrLf & _
"Tag: Demo_TempSetpoint" & 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 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.
SQF Running Project Lab · Blog 07
Read SQF process tags and write SQL status
Dim TempSet, TempAct, FanStatus
TempSet = HMIRuntime.Tags("Temp_Set").Read
TempAct = HMIRuntime.Tags("Temp_Act").Read
FanStatus = HMIRuntime.Tags("Fan_Status").Read
If TempAct >= TempSet Then
HMIRuntime.Tags("SQL_Status").Write "TEMP READY"
End If
Easy TestEasy Test 4 — InputBox + MsgBox
Write is simulated to avoid accidental equipment commands during beginner testing.
Dim TestValue
TestValue = InputBox("Enter value to test for WinCC tag: Temp_Set", "Easy Test 4 — InputBox + MsgBox", "1")
If TestValue = "" Then
MsgBox "Test cancelled.", vbInformation, "Tag Write Quick Test"
Else
MsgBox "SIMULATION ONLY" & vbCrLf & _
"Tag: Temp_Set" & 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