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

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

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

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.

Build reliable WinCC VBScript projects

Join practical online, classroom or corporate training.

Request Course Details
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