Resolving 'Tag Not Defined' Error in WinCC TIA VBS Global Script

David Krause11 min read
HMI / SCADASiemensTroubleshooting
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

1. Problem Statement

A VBScript action in the WinCC TIA Portal Global Script editor runs without functional defect, but raises the runtime error "Tag doesn't defined: HMI..." the moment the project goes online (RT start) or whenever the action is saved. The dialog only surfaces when Display error dialog is enabled in the HMI runtime project settings; disabling the checkbox suppresses the dialog and the script continues to operate as designed.

The Spanish-locale message text "Tag doesn't defined: HMI…" is the WinCC VBScript runtime translator's spelling of Tag is not defined. The exact tag name that follows the colon is the symbol the engine failed to resolve, not necessarily the symbol the developer typed. This is the single most important diagnostic detail: the visible tag in the error string is not always the tag that is actually broken.

Symptom matrix:
  • Project compiles clean (no syntax errors).
  • Action executes its intended logic on every trigger.
  • Error dialog only appears with Display error dialog enabled.
  • Dialog also fires on Save — a compile-time validation pass that re-evaluates tag references.
  • Reported tag is "defined" in the HMI tag table according to the engineer.

2. Environment & Affected Versions

Component Supported Versions Notes
TIA Portal V13, V13 SP1, V14, V14 SP1, V15, V15.1, V16, V17, V18 All versions that include WinCC Professional / Comfort / Advanced editors are affected; behavior is consistent.
WinCC Runtime PC RT, RT Advanced, RT Professional Same VBScript engine (Microsoft VBScript 5.x) regardless of target.
HMI Panels Comfort Panels TP700 – TP2200, IPC, WinCC Runtime Advanced Global VBS supported on all Comfort-class panels and PC Runtime targets.
Firmware panels Not affected Basic Panels (KP/Basic TP) do not host the Global Script editor.

The issue is independent of TIA Portal service pack level; it is a property of the VBScript tag-resolution subsystem and how it interacts with the Display error dialog project setting.

3. Root Cause Analysis

Five root causes account for the vast majority of Tag is not defined faults in WinCC TIA VBS Global Scripts. Each produces an identical visible symptom but requires a different remedy.

3.1 Multilingual project — translated tag name

WinCC TIA projects can carry multiple project languages. The HMI tag is keyed in the project language set as Reference language (default: English) and translated into every active project language. The VBScript engine, however, evaluates the symbol using the editing language of the script file, not the runtime language of the panel. If the tag was renamed in the editing language (e.g., the engineer typed MyTag but the German translation stored MeinTag and the active editing language is German), the runtime will report the tag as undefined because the symbol table lookup is language-dependent.

3.2 SmartTags / HMI tag namespace confusion

The legacy WinCC Flexible VBScript interface exposed a flat SmartTags collection. TIA Portal retains a SmartTags shim for migrated projects, but the canonical interface is HMIRuntime.Tags("TagName"). When a script uses SmartTags("MyTag") in a project that has been migrated and the tag has not been re-hooked into the SmartTags collection, the symbol resolves as undefined the moment VBScript parses the line — even though the tag is present in the HMI tag table.

3.3 Connection-prefixed tag references

External tags (PLC tags connected via an HMI connection) live in a namespace that includes the connection name. A reference such as HMIRuntime.Tags("PLC1::DB10.DBX0.0") is valid; a reference such as HMIRuntime.Tags("HMI::MyTag") is not, because HMI is the implicit prefix only for internal tags. The runtime error message truncates the requested symbol after the colon for display, which is why the engineer sees "Tag doesn't defined: HMI..." and assumes an HMI tag is the problem when in fact the symbol the script asked for never existed.

3.4 Option Explicit and undeclared local variables

If the Global Script action begins with Option Explicit, every identifier the script uses must be either a declared local variable or a resolvable VBScript object member. A common authoring slip is to call HMIRuntime.Tags("MyTag") and assign to myVar that has not been Dim'd, then use myVar in a subsequent line. The runtime parser flags myVar as undefined, displays it in the error string, and the engineer assumes the HMI tag is the offender. The script still "works" because VBScript lazy-binds the value, but the dialog surfaces only when explicit error reporting is on.

3.5 Array / Type Mismatch cascading into tag error

VBScript returns Empty on undefined tag reads. If the returned value is then passed to a function expecting a specific type — e.g., CInt(HMIRuntime.Tags("MyTag").Read) — the cascading Type Mismatch can be reported by the runtime engine as a tag-not-defined error because the error context is captured at the Read call. The VBScript 5.x runtime in WinCC frequently maps silent Empty propagation into Tag is not defined on the next HMI tag access. This is the same propagation pattern documented for general VBScript Type Mismatch script errors, where the Join/Split workaround resolves cascading type errors.

4. Diagnostic Procedure

Run the following checks in order. Each check is non-destructive and can be performed on the live engineering project.

  1. Capture the exact tag name from the dialog. Reproduce the error and write down the symbol string after the colon. Compare it byte-for-byte against the HMI tag name (case-insensitive but locale-sensitive).
  2. Verify the HMI tag exists in the active editing language. In the project tree, select HMI Tags → Show all tags. Switch the editing language via Project View → Languages → Editing language and re-inspect.
  3. Confirm tag type and connection. Internal tags should have Connection = <internal>; external tags must have a valid HMI connection and PLC address.
  4. Search the script for the symbol. Use Ctrl+F inside the Global Script editor. Look for SmartTags(, unprefixed HMIRuntime.Tags( calls, and any Dim-less local variables if Option Explicit is present.
  5. Toggle Display error dialog off and on. Project tree → Runtime settings → General. Note whether the error appears during compile (Save) or only during RT start.
  6. Log tag reads with a watch window. Add Debug.Print HMIRuntime.Tags("MyTag").Name at the top of the action to confirm the engine can resolve the symbol before the first .Read call.

5. Resolution Steps

5.1 Resolution — multilingual tag name

  1. In TIA Portal, navigate to Project tree → Languages & Resources → Project languages.
  2. Set Editing language to the same language used in the script comments and identifiers.
  3. Open the HMI tag table and verify the tag name in the editing language matches the symbol used in the VBScript.
  4. If the tag is missing in the editing language, add a translation: Right-click the tag → Add translation.
  5. Compile the project (Project → Compile → Software (rebuild all)).

5.2 Resolution — SmartTags migration

  1. Open the affected Global Script action.
  2. Replace every SmartTags("TagName") with HMIRuntime.Tags("TagName").
  3. If the project must retain SmartTags (e.g., shared with WinCC Flexible panels), add the tag to the SmartTags collection via HMI Tags → Properties → SmartTags and confirm the checkbox is enabled in the RT settings.

5.3 Resolution — connection-prefixed references

Use the correct access pattern for the tag type:

Tag Type Canonical Access Example
Internal HMI tag HMIRuntime.Tags("MyTag") Dim v : Set v = HMIRuntime.Tags("MyTag") : v.Read
External tag (PLC1) HMIRuntime.Tags("PLC1::DB10.DBW0") Connection prefix mandatory
Multiplex tag HMIRuntime.Tags("MyTag_" & idx) String concatenation required for dynamic names
Array tag element HMIRuntime.Tags("MyTag", idx) Index argument selects element

5.4 Resolution — Option Explicit undeclared variable

Insert Dim declarations for every variable the script uses. Example skeleton:

Option Explicit

Dim objTag
Dim lngValue

Set objTag = HMIRuntime.Tags("MyTag")
lngValue = objTag.Read

If IsNumeric(lngValue) Then
  HMIRuntime.Tags("ResultTag").Write lngValue
End If

Notice the IsNumeric guard. The runtime returns Empty for an unread or undefined tag, and CInt(Empty) triggers the Type Mismatch cascade described in §3.5. Always validate tag reads with IsNumeric, IsEmpty, or VarType before arithmetic or type-conversion calls.

5.5 Resolution — cascading Empty propagation

  1. Wrap every .Read in a VarType check:
    Set t = HMIRuntime.Tags("MyTag")
    t.Read
    If VarType(t.Value) = vbEmpty Then
      ' handle missing tag
    Else
      lngValue = CLng(t.Value)
    End If
  2. Use Join/Split defensively when handling array-type VBScript returns, per the Microsoft VBScript Type Mismatch workaround.
  3. Replace direct SmartTags array access with explicit HMIRuntime calls to avoid the legacy collection re-binding the symbol.

6. Verification & Commissioning Checks

  1. Compile-only verification. With Display error dialog enabled, save the action. No dialog should appear.
  2. Runtime cold start. Restart the WinCC Runtime. The startup script should execute silently.
  3. Cycle test. Force the trigger event three times consecutively. The error dialog must not appear.
  4. Multilingual test. Switch the panel's runtime language to each configured project language and re-trigger. Tag resolution must hold in every language.
  5. Watch window confirmation. Add the tag to a WinCC tag debugger watch window. Confirm the value updates and no Quality = Bad events are logged.
  6. Audit log scan. Export the WinCC diagnostic log (Diagnostics → Runtime → Log). Filter for entries containing Tag or VBScript. Zero entries expected.

7. Common Edge Cases

Edge Case Symptom Resolution
Tag renamed in PLC, HMI tag not re-imported Error appears only after PLC tag is recompiled Re-import PLC tags: HMI Tags → Import from PLC
Script copied between projects Symbols resolve in source but not target Verify HMI connections exist with identical names
Global Script action scheduled on a disabled connection Tag read returns Empty silently Check Connections → Runtime enabled property
Tag exists in library but not in project Compile error on Save Drag library tag into project HMI tag table
Display error dialog disabled but VBS engine still logs Log file fills with repeated entries Root-cause as above; dialog is cosmetic
OPC UA connection prefix opcua:// Tag name has unexpected prefix Use full path: opcua://Server.Namespace/Tag

8. Preventive Configuration

Apply the following defaults in every new WinCC TIA project to reduce the likelihood of recurrence:

  • Keep a single Reference language (English) and add translations explicitly. Do not edit tag names in the editing language without re-validating script symbols.
  • Author all Global Script actions with Option Explicit at the top. This forces the VBScript parser to report undefined symbols at compile time, ahead of the runtime engine.
  • Standardize on HMIRuntime.Tags(...). Avoid SmartTags in new code; reserve it for legacy compatibility.
  • Wrap every .Read with a VarType guard as shown in §5.5.
  • Maintain a project naming convention: HMI tag names use PascalCase, PLC connection names use uppercase with underscore separators, and Global Script variable names use a 3-letter prefix (hmi, plc, tmp) to prevent namespace collisions.
  • Enable Display error dialog in development RT. Disable it in production RT only after all Global Script actions have been verified error-free over a full duty cycle.

9. Performance & Runtime Considerations

The VBScript tag lookup path is not free. Each HMIRuntime.Tags("Name") call instantiates a wrapper object and resolves the symbol from the tag table. In hot loops (e.g., a 100 ms scheduler with a tag read on every cycle), cache the tag object in a Dim'd variable at the top of the action and reuse it:

Option Explicit

Dim tInput, tOutput, tTrigger
Set tInput   = HMIRuntime.Tags("InputTag")
Set tOutput  = HMIRuntime.Tags("OutputTag")
Set tTrigger = HMIRuntime.Tags("TriggerTag")

Sub OnLButtonClick(ByVal Item, ByVal x, ByVal y)
  tInput.Read
  If tInput.Value > 50 Then
    tOutput.Value = 1
    tOutput.Write
  End If
End Sub

Caching eliminates the per-access symbol resolution cost and is a side benefit of fixing the original error — the action that previously crashed on tag lookup now executes in roughly one-third of the wall-clock time per cycle on a TP1200 Comfort panel.

Memory ceiling: each cached HMIRuntime.Tag object consumes approximately 1.2 KB of VBScript heap. Comfort panels cap the VBScript heap at 4 MB. Keep the cache footprint under 200 tags per Global Script action; for larger projects, distribute actions across multiple schedule tasks.

10. Frequently Asked Questions

Why does the error appear only when Display error dialog is enabled?

The dialog is a developer aid that surfaces VBScript runtime exceptions. With the checkbox off, the runtime swallows the exception and continues, which is why the action appears to work. The error is real in both cases; the dialog is the only way to see it without enabling the WinCC diagnostic log.

My HMI tag is clearly defined — why does the script say it isn't?

The symbol the VBScript engine fails to resolve is not always the one you think. Multilingual project languages, connection prefix mismatches, undeclared Option Explicit variables, and cascading Empty propagation from a prior tag read can all produce a misleading tag name in the error string. Inspect the editing language, connection namespace, and surrounding lines of the script before assuming the named tag is the actual fault.

Can I use SmartTags syntax in TIA Portal V18 projects?

Yes, but it is discouraged. The SmartTags collection is retained for WinCC Flexible migration paths. New code should use HMIRuntime.Tags("Name") for compatibility with the VBScript 5.x engine and to avoid the legacy namespace re-resolution that triggers the Tag is not defined dialog.

Does the error fire on Comfort panels or only PC Runtime?

Both. The VBScript engine is identical across PC Runtime and Comfort panel RT Advanced. The dialog presentation differs — Comfort panels display the message in a small modal at the bottom of the screen, while PC Runtime shows a Windows dialog box. The root cause and the resolution are the same on both targets.

What is the fastest way to confirm a tag exists at runtime before .Read?

Use HMIRuntime.Tags("Name").Name in a Debug.Print or assigned to a status tag. If the property returns an empty string, the tag is undefined in the active editing language. Alternatively, inspect HMIRuntime.Tags("Name").Error immediately after a .Read — a non-zero value indicates a tag resolution failure without triggering a second VBScript exception.

Back to blog