WinCC VBScript Error Handling and Runtime Diagnostics
This lab targets wincc vbscript error handling with copy-ready examples, expected results and diagnostic guidance.
1. Use Err Handling in a Small Scope
On Error Resume Next suppresses automatic interruption, so check Err.Number immediately after the operation that can fail. Clear the error and restore normal handling with On Error GoTo 0.
On Error Resume Next
Dim demoTag
Set demoTag = HMIRuntime.Tags("Demo_Temperature")
demoTag.Read
If Err.Number <> 0 Then
HMIRuntime.Trace "Read error " & CStr(Err.Number) & _
": " & Err.Description
Err.Clear
End If
Set demoTag = Nothing
On Error GoTo 0
2. Inspect WinCC Tag Diagnostics
After a tag operation, inspect LastError and ErrorDescription on the tag object. For data validity, record QualityCode and TimeStamp along with the value.
3. Write Useful HMIRuntime.Trace Messages
Sub TraceFailure(ByVal actionName, ByVal errorNumber, ByVal description)
HMIRuntime.Trace "VBS|" & actionName & _
"|Err=" & CStr(errorNumber) & _
"|" & description
End SubA consistent prefix makes diagnostics searchable. Include the action, operation and tag or file name, but never log passwords or sensitive connection-string fields.
4. Clean Up COM Objects on Every Path
Files, ADODB connections, recordsets and Excel objects need deterministic closure. Close child objects before parent objects, set references to Nothing, and include cleanup after both success and failure.
5. Common Runtime Error Map
| Error | Likely cause |
|---|---|
| Object required | Missing Set, wrong screen item or failed COM creation |
| Type mismatch | Unchecked conversion of Empty, text or invalid process data |
| Permission denied | Runtime identity cannot access the file, database or folder |
| ActiveX component cannot create object | Provider/application missing, bitness mismatch or COM registration issue |
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.
