Learning Foundation: Safe Operator Interaction
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.
Conversions, decision logic, tag writes and error handling.
Operator input is untrusted data. Validate format, range and process context before writing setpoints or command requests. PLC-side interlocks remain authoritative.
Validate furnace number, temperature/CP setpoints and start/stop requests before writing to WinCC tags.
Implement InputBox validation, range checks, confirmations and HMI command gating without bypassing PLC permissives.
Receive entered value/request
Reject invalid text
Apply engineering bounds
Check intent/context
Write only approved request
Complete WinCC VBScript Learning Path
Use Previous/Next for the recommended practical order, or open any topic below as a reference.
WinCC VBScript operator input validation and command gating
This practical guide explains how to validate operator-entered values and control HMI command availability without moving equipment protection or safety logic out of the PLC.
1. Separate HMI validation from PLC command authorization
An HMI can check whether a value looks reasonable and explain why a button is unavailable. It cannot be the only layer preventing an unsafe command. Treat every HMI write as an external request that the PLC must validate.
| Layer | Recommended responsibility |
|---|---|
| WinCC screen | Input format, engineering range, confirmation and operator feedback |
| WinCC User Administration | Role-based access to approved HMI actions |
| PLC program | Mode, sequence, permissive, interlock and command acceptance |
| Safety system | Safety functions and risk-reduction measures |
2. Validate numeric operator input before writing a tag
Read the proposed input, confirm it is numeric, convert it explicitly and reject values outside the approved engineering range.
Function ValidateSetpoint(ByVal proposedValue, ByVal lowLimit, ByVal highLimit)
ValidateSetpoint = False
If Not IsNumeric(proposedValue) Then Exit Function
Dim value
value = CDbl(proposedValue)
If value < CDbl(lowLimit) Or value > CDbl(highLimit) Then Exit Function
ValidateSetpoint = True
End Function
Easy TestEasy Test 1 — 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 1 — InputBox + MsgBox", "850"))
PV = CDbl(InputBox("Enter Actual Value", "Easy Test 1 — InputBox + MsgBox", "825"))
MsgBox "Setpoint = " & SP & vbCrLf & _
"Actual = " & PV & vbCrLf & _
"Function Result = " & TestIsOK(SP, PV), _
vbInformation, "Function Quick Test"Display the engineering unit and permitted range next to the entry field. Do not silently clamp an operator value unless the approved functional specification explicitly requires it.
3. Write only after validation and confirmation
Sub WriteApprovedSetpoint(ByVal proposedValue)
If Not ValidateSetpoint(proposedValue, 0, 100) Then
HMIRuntime.Trace "Setpoint rejected: invalid range" & vbCrLf
Exit Sub
End If
If MsgBox("Apply setpoint " & CStr(proposedValue) & " %?", _
vbQuestion + vbYesNo, "Confirm setpoint") = vbYes Then
HMIRuntime.Tags("HMI_Setpoint_Request").Write CDbl(proposedValue)
HMIRuntime.Trace "Setpoint request submitted" & vbCrLf
End If
End Sub
Easy TestEasy Test 2 — InputBox + MsgBox
Write is simulated to avoid accidental equipment commands during beginner testing.
Dim TestValue
TestValue = InputBox("Enter value to test for WinCC tag: HMI_Setpoint_Request", "Easy Test 2 — InputBox + MsgBox", "1")
If TestValue = "" Then
MsgBox "Test cancelled.", vbInformation, "Tag Write Quick Test"
Else
MsgBox "SIMULATION ONLY" & vbCrLf & _
"Tag: HMI_Setpoint_Request" & 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 IfConfirmation is most useful for consequential or infrequent actions. Avoid interrupting routine operation with unnecessary dialogs.
4. Gate an HMI command from displayed operating state
A button may be disabled when the displayed machine mode or readiness state is unsuitable. This gives immediate feedback but remains separate from PLC acceptance.
Function CanRequestStart()
Dim modeValue, readyValue
modeValue = HMIRuntime.Tags("Machine_Mode").Read
readyValue = HMIRuntime.Tags("Machine_Ready").Read
CanRequestStart = (modeValue = 2 And readyValue = 1)
End Function
Easy TestEasy Test 3 — InputBox + MsgBox
Offline tag simulation: useful before connecting the participant PC to WinCC Runtime.
Dim TestValue, ResultText
ResultText = ""
TestValue = InputBox("Enter simulated value for Machine_Mode", "Easy Test 3 — InputBox + MsgBox", "TEST")
ResultText = ResultText & "Machine_Mode = " & TestValue & vbCrLf
TestValue = InputBox("Enter simulated value for Machine_Ready", "Easy Test 3 — InputBox + MsgBox", "TEST")
ResultText = ResultText & "Machine_Ready = " & TestValue & vbCrLf
MsgBox ResultText & vbCrLf & "Now compare these values with the original HMIRuntime .Read example.", vbInformation, "Tag Read Quick Test"Use explicit state values or documented constants. Avoid unexplained numeric values in production libraries.
5. Apply user authorization correctly
Configure permissions in WinCC User Administration and use the supported authorization dynamic or object-model method for the installed release. Test authorized, unauthorized, expired-session and logged-out states.
- Show why the action is unavailable.
- Log consequential command requests with user and timestamp where required.
- Never treat a hidden button as a security boundary.
6. Use request and acknowledgment tags
For important commands, use a PLC handshake instead of assuming that a successful HMI write means the action occurred.
- WinCC writes a command request and optional request identifier.
- The PLC validates mode, permissives and interlocks.
- The PLC accepts or rejects the request.
- WinCC displays acknowledgment, rejection reason or timeout.
7. Test invalid, stale and unavailable states
| Test | Expected HMI behavior |
|---|---|
| Text entered in numeric field | Reject without writing |
| Value outside engineering range | Show allowed range and preserve previous approved value |
| Communication unavailable | Disable request and show connection state |
| User lacks permission | Prevent interaction and show authorization feedback |
| PLC rejects command | Display the returned reason or timeout state |
8. Commissioning checklist
- Document every command tag, unit, range and data type.
- Confirm the PLC validates every HMI request independently.
- Test boundary values, invalid text, communication loss and user-role changes.
- Confirm scripts do not issue repeated writes from cyclic triggers.
- Record approved behavior in the functional specification and backup.
Frequently asked questions
Is disabling a WinCC button an interlock?
No. It is operator-interface feedback. The PLC or safety system must enforce the actual interlock.
Should invalid input be automatically corrected?
Usually it should be rejected with a clear message. Automatic clamping can conceal an entry mistake unless it is explicitly required and documented.
Can VBScript check user permissions?
Yes, where supported by the installed WinCC object model. Prefer configured authorization dynamics and verify the exact API for the deployed release.
SQF Running Project Lab · Blog 09
Validate ChargeNo before saving
Dim Charge
Charge = Trim(CStr(HMIRuntime.Tags("ChargeNo").Read))
If Charge = "" Then
MsgBox "Charge Number is required."
Exit Sub
End If
Easy TestEasy Test 4 — InputBox + MsgBox
Offline tag simulation: useful before connecting the participant PC to WinCC Runtime.
Dim TestValue, ResultText
ResultText = ""
TestValue = InputBox("Enter simulated value for ChargeNo", "Easy Test 4 — InputBox + MsgBox", "TEST")
ResultText = ResultText & "ChargeNo = " & TestValue & vbCrLf
MsgBox ResultText & vbCrLf & "Now compare these values with the original HMIRuntime .Read example.", vbInformation, "Tag Read Quick Test"