<!-- Softwell WinCC VBScript 20-Part Tutorial · Blog 14 · updated 2026-08-29 --> WinCC VBScript Error Handling & Diagnostics | Softwell
WinCC Explorer · VBScript · Practical Tutorial

WinCC VBScript Error Handling and Runtime Diagnostics

Diagnose WinCC VBScript errors using Err, LastError, ErrorDescription and HMIRuntime.Trace, with solutions for common Runtime failures.

Lab Overview

WinCC VBS Lab 4Estimated time: 60 minutesDifficulty: Intermediate

Prerequisites / What You’ll Need

  • Backed-up WinCC Explorer test project
  • Graphics Designer and Global Script VBS access
  • Internal test tags and Runtime diagnostics

Learning Foundation: Reliability & Diagnostics

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.

IntermediateWinCC Explorer / Classic WinCCSQF Running Project
Prerequisite

Runtime tag access and Global Script execution concepts.

Core concept

VBScript errors must be detected close to the operation that can fail. On Error Resume Next is useful only when paired with immediate Err checks, diagnostics and cleanup.

SQF practical connection

Diagnose missing tags, invalid values, failed file operations and SQL connection errors without hiding faults.

Expected competency

Use Err.Number, Err.Description, Err.Clear, HMIRuntime.Trace and cleanup patterns to make scripts supportable.

WinCC VBScript Error Handling and Runtime Diagnostics — ArchitectureCode-rendered HTML/CSS architecture; no image file required
Operation

Attempt tag/file/SQL work

On Error Resume Next
Check

Inspect immediately

If Err.Number <> 0
Diagnose

Record useful context

HMIRuntime.Trace
Recover

Clear/fallback/exit

Err.Clear
Cleanup

Release objects/resources

Set Conn = Nothing

Complete WinCC VBScript Learning Path

Use Previous/Next for the recommended practical order, or open any topic below as a reference.

WinCC VB Scripting Training →
Easy Testing Method: Every main code example on this page is followed by a copy-ready InputBox + MsgBox test. Use the dialog version first to understand the result, then move to the original WinCC/SQL code. Database writes and equipment commands are previewed or simulated unless the original example is already intended as a lab action.

WinCC VBScript Error Handling and Runtime Diagnostics

This lab targets wincc vbscript error handling with copy-ready examples, expected results and diagnostic guidance.

Safety: Test on internal tags or an approved simulation system. Do not bypass PLC permissives, interlocks, user authorization or plant change control.

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

Easy TestEasy Test 1 — 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 1 — InputBox + MsgBox", "10"))
B = CDbl(InputBox("Enter divisor (try 0)", "Easy Test 1 — 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 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 Sub

Easy TestEasy Test 2 — 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 2 — InputBox + MsgBox", "825.5")
Call ShowSQFValue("Temp_Act", TempAct)

A 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

ErrorLikely cause
Object requiredMissing Set, wrong screen item or failed COM creation
Type mismatchUnchecked conversion of Empty, text or invalid process data
Permission deniedRuntime identity cannot access the file, database or folder
ActiveX component cannot create objectProvider/application missing, bitness mismatch or COM registration issue

Hands-On Verification Lab

Hands-on
1

Prepare a controlled test

Create only the internal tags, folders or disposable database rows required by this tutorial.

The test scope is isolated and documented.
2

Run the smallest example

Execute one operation and inspect WinCC diagnostics before expanding the script.

The expected value, file, object or database result appears once.
3

Test a failure path

Use a safe backup copy to test an invalid tag, path or disposable input.

The script records a useful error and cleans up without an uncontrolled action.

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.

Get the WinCC VB Scripting syllabus

Share your details and a Softwell advisor will contact you with training options.

SQF Running Project Lab · Blog 14

Return SQL feedback to WinCC

On Error Resume Next
Err.Clear

'Risky operation here

If Err.Number <> 0 Then
    HMIRuntime.Tags("SQL_Status").Write "FAILED"
    HMIRuntime.Trace Err.Description & vbCrLf
    Err.Clear
Else
    HMIRuntime.Tags("SQL_Status").Write "OK"
End If

On Error GoTo 0

Easy TestEasy Test 3 — 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 3 — InputBox + MsgBox", "10"))
B = CDbl(InputBox("Enter divisor (try 0)", "Easy Test 3 — 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 0
Check Err.Number immediately after the operation you are diagnosing.

Build reliable WinCC VBScript projects

Join practical online, classroom or corporate training.

Request Course Details
WinCC VBScript Learning Path 5 of 10

Runtime diagnostics and recovery: engineering guide

Use scoped error handling, Err inspection and HMIRuntime.Trace to expose failures without hiding unsafe or incomplete operations.

Implementation and commissioning checklist

Practical completion outcome

A reusable diagnostic pattern that identifies the failed operation and leaves Runtime resources in a known state.

Safety boundary: Validate scripts on a backed-up WinCC training or staging project. PLC safety functions, permissives and interlocks must remain independent of HMI scripting.

Verified learning pathway

Discuss WinCC VB Scripting Training

Explore practical WinCC VBS, SCADA, SQL reporting and industrial automation training options.

Content reviewed: 4 August 2026

☎ Call WhatsApp ✉ Email Enquire Now