Learning Foundation: Alarm Context & Response
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.
Tag access, navigation and diagnostics. Understand that core alarms are configured in WinCC Alarm Logging.
VBScript should support—not replace—the configured alarm system by adding context, navigation, trace/audit actions and controlled auxiliary logging.
Use furnace fault/status tags to navigate to the correct equipment and record diagnostic context around alarm events.
Integrate VBScript with WinCC alarm workflows without building safety/alarm truth solely in script.
PLC/WinCC condition occurs
Configured alarm becomes active
Read equipment/process context
Navigate/show details
Trace or SQL record
Complete WinCC VBScript Learning Path
Use Previous/Next for the recommended practical order, or open any topic below as a reference.
WinCC VBScript alarm and event handling
This guide explains where VBS can support alarm diagnostics, operator navigation and custom event records while WinCC Alarm Logging remains responsible for alarm state, timestamp, acknowledgment and archive behavior.
1. Define the alarm lifecycle before adding VBScript
Every alarm should have a documented source, priority, message, operator response, acknowledgment rule and return-to-normal behavior. Configure these functions in WinCC Alarm Logging wherever possible.
| Requirement | Preferred WinCC mechanism | Possible VBS support |
|---|---|---|
| Alarm state and timestamp | Alarm Logging | None required |
| Alarm acknowledgment | Configured alarm control | Supplementary navigation or context only |
| Alarm archive | Alarm archive or approved historian | Optional secondary event record |
| Diagnostic guidance | Alarm text and help | Open a related diagnostic view |
| Custom notification | Approved notification subsystem | Trigger a bounded, reviewed action |
2. Read alarm context from approved tags
When a supplementary action is required, read a small set of explicit context tags rather than reconstructing the entire alarm state in VBS.
Function ReadAlarmContext()
Dim alarmActive, equipmentId, faultCode
alarmActive = HMIRuntime.Tags("Alarm_Active").Read
equipmentId = HMIRuntime.Tags("Alarm_EquipmentId").Read
faultCode = HMIRuntime.Tags("Alarm_FaultCode").Read
ReadAlarmContext = CStr(alarmActive) & "|" & _
CStr(equipmentId) & "|" & CStr(faultCode)
End Function
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 Alarm_Active", "Easy Test 1 — InputBox + MsgBox", "TEST")
ResultText = ResultText & "Alarm_Active = " & TestValue & vbCrLf
TestValue = InputBox("Enter simulated value for Alarm_EquipmentId", "Easy Test 1 — InputBox + MsgBox", "TEST")
ResultText = ResultText & "Alarm_EquipmentId = " & TestValue & vbCrLf
TestValue = InputBox("Enter simulated value for Alarm_FaultCode", "Easy Test 1 — InputBox + MsgBox", "TEST")
ResultText = ResultText & "Alarm_FaultCode = " & TestValue & vbCrLf
MsgBox ResultText & vbCrLf & "Now compare these values with the original HMIRuntime .Read example.", vbInformation, "Tag Read Quick Test"Confirm tag quality and data type in the deployed release. The configured alarm remains authoritative even if this supplementary read fails.
3. Open contextual diagnostics without creating popup storms
A high-priority alarm may offer a button that opens the relevant equipment diagnostic view. Avoid opening repeated modal windows automatically for every state change.
Sub RequestAlarmDiagnostic(ByVal equipmentId)
If Trim(CStr(equipmentId)) = "" Then
HMIRuntime.Trace "Diagnostic request rejected: no equipment" & vbCrLf
Exit Sub
End If
HMIRuntime.Tags("UI_SelectedEquipment").Write CStr(equipmentId)
'Call the supported popup or picture-window method for this WinCC release.
HMIRuntime.Trace "Alarm diagnostic requested for " & _
CStr(equipmentId) & vbCrLf
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: UI_SelectedEquipment", "Easy Test 2 — InputBox + MsgBox", "1")
If TestValue = "" Then
MsgBox "Test cancelled.", vbInformation, "Tag Write Quick Test"
Else
MsgBox "SIMULATION ONLY" & vbCrLf & _
"Tag: UI_SelectedEquipment" & 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 a validated equipment map and the navigation pattern described in WinCC screen navigation, faceplates and reusable instances.
4. Record a supplementary event with stable fields
A custom record may capture diagnostic context not contained in the standard alarm message. Use a stable schema and avoid storing sensitive operator information unnecessarily.
Sub TraceAlarmEvent(ByVal equipmentId, ByVal faultCode, ByVal actionName)
Dim eventLine
eventLine = "ALARM_EVENT|equipment=" & CStr(equipmentId) & _
"|fault=" & CStr(faultCode) & _
"|action=" & CStr(actionName)
HMIRuntime.Trace eventLine & vbCrLf
End Sub
Easy TestEasy Test 3 — InputBox + MsgBox
Self-contained procedure test; no PLC or SQL Server is required.
Sub ShowSQFValue(ByVal NameText, ByVal ValueText)
MsgBox NameText & " = " & ValueText, vbInformation, "Sub Quick Test"
End Sub
Dim TempAct
TempAct = InputBox("Enter Temp_Act", "Easy Test 3 — InputBox + MsgBox", "825.5")
Call ShowSQFValue("Temp_Act", TempAct)For durable records, use the configured alarm archive, historian or approved database. HMIRuntime.Trace is primarily a diagnostic aid, not a compliance archive.
5. Support acknowledgment without bypassing WinCC controls
Use the supported alarm-control acknowledgment function and configured authorization. A script may prepare context or navigate to the alarm control, but it should not create an undocumented parallel acknowledgment mechanism.
- Require the configured role for acknowledgment.
- Preserve alarm identity, original timestamp and acknowledgment timestamp.
- Do not acknowledge alarms automatically merely because a popup was opened.
- Test acknowledgment during communication loss and redundant-server changeover where applicable.
6. Design sounds and notifications conservatively
Custom sounds or external notifications must be bounded, rate-limited and aligned with the alarm philosophy. Repeated script triggers can create duplicate notifications or operator overload.
- Trigger on a defined state transition, not every cyclic evaluation.
- Record delivery success and failure separately from alarm acknowledgment.
- Provide a supported silence or escalation workflow.
- Do not transmit plant or operator data to external services without approval.
7. Handle event-script failures explicitly
An error in a supporting script must not suppress the configured alarm. Keep the action small, trace the failing operation and clean up external objects.
Sub RunAlarmSupportAction()
On Error Resume Next
Err.Clear
Call TraceAlarmEvent("M101", 27, "OPEN_DIAGNOSTIC")
If Err.Number <> 0 Then
HMIRuntime.Trace "Alarm support error " & CStr(Err.Number) & _
": " & Err.Description & vbCrLf
Err.Clear
End If
On Error GoTo 0
End Sub
Easy TestEasy Test 4 — InputBox + MsgBox
Enter 0 as the divisor to deliberately generate and observe a VBScript error.
On Error Resume Next
Dim A, B, Result
A = CDbl(InputBox("Enter numerator", "Easy Test 4 — InputBox + MsgBox", "10"))
B = CDbl(InputBox("Enter divisor (try 0)", "Easy Test 4 — InputBox + MsgBox", "0"))
Result = A / B
If Err.Number <> 0 Then
MsgBox "Error " & Err.Number & vbCrLf & Err.Description, vbExclamation, "Error Quick Test"
Err.Clear
Else
MsgBox "Result = " & Result, vbInformation, "Error Quick Test"
End If
On Error GoTo 0Continue with WinCC VBScript error handling and diagnostics for reusable failure patterns.
8. Test alarm transitions and recovery states
| Test condition | Expected result |
|---|---|
| Alarm arrives | Configured alarm appears once with correct priority and timestamp |
| Supporting script fails | Alarm remains visible and script error is traceable |
| Alarm clears before acknowledgment | Lifecycle follows configured policy |
| Unauthorized acknowledgment | Request is rejected and alarm remains active or unacknowledged |
| Communication loss | Bad-quality or connection alarm behavior is explicit |
| Alarm burst | No uncontrolled popup, sound or notification repetition |
9. Commissioning checklist
- Review the alarm against the site alarm philosophy.
- Confirm WinCC Alarm Logging owns lifecycle and acknowledgment.
- Verify supplementary scripts are transition-based and bounded.
- Test every user role and abnormal communication state.
- Confirm custom records do not conflict with the approved historian.
- Document triggers, context tags, navigation targets and failure behavior.
10. Example: bottling-line filler fault
A filler motor overload creates a configured WinCC alarm with priority, timestamp and acknowledgment requirements. The operator can open a motor-specific diagnostic faceplate, while a supporting VBS action traces the equipment identifier and fault code. Clearing or acknowledging the alarm still follows the configured alarm lifecycle; the script does not reset the drive or bypass the PLC fault logic.
Frequently asked questions
Should VBScript create every WinCC alarm?
No. Configure process alarms through WinCC Alarm Logging. Use VBS only for justified supplementary behavior.
Can a script automatically acknowledge an alarm?
That is generally inappropriate unless explicitly required, authorized and supported by the approved alarm philosophy. Preserve the standard acknowledgment audit trail.
Is HMIRuntime.Trace an alarm historian?
No. It is useful for Runtime diagnostics. Use Alarm Logging, a historian or an approved database for durable records.
How can popup storms be prevented?
Prefer operator-requested diagnostics, trigger on transitions, check whether the view is already open and rate-limit supplementary notifications.
SQF Running Project Lab · Blog 12
Map an SQF state transition
Dim EventFrom, EventTo, FanStatus
FanStatus = HMIRuntime.Tags("Fan_Status").Read
If FanStatus Then
EventFrom = "FAN STOP"
EventTo = "FAN START"
Else
EventFrom = "FAN START"
EventTo = "FAN STOP"
End If
Easy TestEasy Test 5 — InputBox + MsgBox
Offline tag simulation: useful before connecting the participant PC to WinCC Runtime.
Dim TestValue, ResultText
ResultText = ""
TestValue = InputBox("Enter simulated value for Fan_Status", "Easy Test 5 — InputBox + MsgBox", "1")
ResultText = ResultText & "Fan_Status = " & TestValue & vbCrLf
MsgBox ResultText & vbCrLf & "Now compare these values with the original HMIRuntime .Read example.", vbInformation, "Tag Read Quick Test"Event_From and Event_To fields later become SQL history columns.