Configuring TAG_PREFIX on WinCC OnlineTrendControl via VBS

David Krause15 min read
HMI / SCADASiemensTutorial / How-to
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

Configuring TAG_PREFIX on WinCC OnlineTrendControl via VBS

The WinCC OnlineTrendControl (formerly distributed as the ActiveX AxOnlineTrendControl in classic WinCC) does not automatically inherit the TagPrefix property of its parent picture window. Engineers who embed a trend view inside a picture window expecting the standard {prefix} ag substitution — the same behavior that I/O fields, text fields, and bar graphs receive — find that the trend control silently ignores the prefix and shows no data, no error, and no warning in the compiler. This article documents the root cause, the official object-model documentation path, and the VBS workarounds that allow runtime control of trend tag names with a configurable prefix.

1. Overview of the Limitation

Picture windows in TIA Portal (WinCC Comfort, WinCC RT Advanced, WinCC RT Professional, and the corresponding HMI panel families) accept a TagPrefix string property. Tags referenced inside the embedded screen are rewritten at compile/runtime with the prefix prepended, so the same screen can be reused for many different data contexts by changing only the picture-window prefix. According to the TIA Portal V20 VBS object model documentation, this property:

"Specifies the tag prefix that is prefixed for all tags contained in the screen window. In this way, a screen that is embedded in a screen window retains access ..." — TIA Portal V20 VBS Reference — TagPrefix property

The OnlineTrendControl violates this implicit contract. The control's curve TrendTagName field is treated as a literal qualified path: either a fully qualified PLC tag (e.g., "S7-1500S/PLC_1::DB1.HMI_Data.OilTemp") or a tag-logging archive path (e.g., "OIL_LOG\OilTemp"). The picture-window prefix substitution engine does not perform the rewrite for this control. The visible symptom is:

  • The trend window opens, axes render, time grid renders, but no curve line is drawn.
  • The Configuration > Select Trends dialog shows the curve entry with the unresolved tag name (e.g., {prefix}\OilTemp).
  • No compiler error, no runtime error code — the tag simply cannot be resolved against the underlying S7 connection or tag-logging archive.

2. Prerequisites

Before applying any VBS workaround, verify the following:

Item Requirement Notes
TIA Portal V15.1 or later; V16–V20 verified for object model Older portal versions (V13, V14) used the legacy AxOnlineTrendControl COM interface with the same limitation
WinCC Runtime Comfort Panel, RT Advanced, or RT Professional Same object model across platforms; runtime properties differ in availability
Project scripting Enable VBScript on the HMI device HMI device → Runtime settings → Scripts → Activate VBScript
ActiveX / Trend controls ActiveX controls enabled in runtime RT Advanced / Panels: built-in; RT Professional: confirm ActiveX is enabled under runtime security
Reference manual WinCC: Scripting (VBS, ANSI-C, VBA) — System Manual, 11/2020, A5E50503017-AA Section 1.14 documents the GetTrend() method and trend-curve properties
Tag logging Configured archive with the target tag Tag name spelling must match exactly — case-sensitive on some panels
Note: In WinCC V7 / WinCC Professional (TIA Portal predecessor), the ActiveX CCAxOnlineTrendControl.OnlineTrendControl.1 had a different namespace and required ScreenItems("Control1").GetTrend(0) with Set assignment. The same limitation applied — the picture-window TagPrefix was never substituted for the trend-tag property.

3. Understanding the WinCC VBS Object Model for Trends

The OnlineTrendControl exposes a hierarchical object model that mirrors the visual structure: a control object (the widget itself) and a collection of trend-curve objects, each with its own data source, color, and visibility state. The two most important access patterns are listed below.

3.1 Control-Level Object

The control is reached through the ScreenItems collection by the name assigned at configuration time (default Control1, but the engineer may rename it). Its top-level properties are read/write from VBS.

3.2 Curve-Level Object via GetTrend()

The GetTrend(Index) method returns a trend-curve object. Indices are 0-based. If a trend control was configured with 3 curves in the configuration dialog, valid indices are 0, 1, and 2 regardless of the curve's position in the configuration list.

The following inline diagram shows the object hierarchy:

HMIRuntime ScreenItems Item("Control1") GetTrend(0) GetTrend(1) GetTrend(2) TrendTagName TrendColor TrendVisible Curve 0 — assigned to "TAGGLOGGING_ARCHIVE\OilTemp", red, visible Curve 1 — assigned to "TAGGLOGGING_ARCHIVE\Pressure", green, hidden Curve 2 — placeholder, no tag yet, hidden until VBS attaches a source

The properties that control curve content and visibility are documented in the scripting manual A5E50503017-AA, section 1.14, pages 577–585 of the 11/2020 release.

4. Root Cause: Why TAG_PREFIX is Ignored

The picture-window tag-prefix substitution is implemented in the screen compiler for properties that are registered as "tag-evaluable" — IO fields, text fields, bar graphs, gauges, and similar dynamic widgets. The OnlineTrendControl is registered as an ActiveX / OCX-based control with its own internal storage for curve configuration. The compiler hands the entire curve data structure to the control as a binary blob, and the prefix substitution engine treats it as an opaque payload because the TrendTagName field can legitimately contain non-tag content (archive paths, formula references, server prefixes, etc.).

The same blind spot applies to:

  • AxBarChartControl — value column tag source
  • AxFunctionTrendControl — f(x) tag source
  • AxOnlineTableControl — column tag source
  • AxAlarmControl — server name and message filter

The control is unaware that a prefix was expected. The screen compiler will not refuse to download the project; the runtime will not raise an alarm; the trend window will simply draw an empty canvas.

5. Solution 1 — Embed the Prefix Manually in TrendTagName

The cleanest solution is to construct the full tag name at configuration time, including whatever prefix the picture window would have applied. The TrendTagName field accepts both formats described below.

5.1 Tag-Logging Archive Path

For tags stored in a WinCC tag-logging archive, the syntax is "<ArchiveName>\<TagName>". The prefix is inserted before the tag name:

TAGGLOGGING_ARCHIVE\Line1.OilTemp

If the picture-window prefix is Line1, the value above is what you would type directly into the Tag Name column of the Configuration > Trends dialog at design time. The control does not see the prefix — only the resolved path.

5.2 Direct PLC Connection Path

For a live (non-archived) tag, use the connection-qualified path:

S7-1500S/PLC_1::DB1.HMI_Data.OilTemp

This bypasses the archive entirely and reads the live PLC value. Useful for short-term trending on tags that are not logged.

5.3 When the Prefix Varies at Runtime

If the prefix is a runtime variable (for example, the operator selects which production line to view from a dropdown), the configuration-time manual approach fails. Use Solution 2 below.

6. Solution 2 — Dynamic Trend Curve Configuration via VBS

Build a single OnlineTrendControl with the maximum number of curves you will ever display. At runtime, use VBS to assign each curve's TrendTagName from a calculated string that includes the active prefix, and toggle the TrendVisible flag per curve.

6.1 Initialize the Control with N Placeholder Curves

  1. Open the trend control's configuration dialog.
  2. In the Trends tab, add the maximum number of curves you will ever need (e.g., 8).
  3. For each curve, give a descriptive Object name (e.g., Curve_OilTemp, Curve_Pressure). The Object name is the title shown in the legend; the Tag name is left blank or set to a placeholder.
  4. Set the curve's Display property to Off so it does not draw before VBS sets it up.

6.2 Attach Tags and Visibility via VBS

The following script demonstrates the canonical pattern: read the active prefix from an HMI tag, loop over the configured curves, and set both the data source and the visibility flag.

' VBScript — Configure trends on Open event of the screen
' Place this on the "Open" event of the screen that contains Control1

Dim objCtrl
Dim objCurve
Dim strPrefix
Dim i

Set objCtrl = ScreenItems.Item("Control1")

' Read the active prefix from an HMI tag; default is empty
strPrefix = SmartTags("ActiveTagPrefix")

' Configure 3 curves — adjust count to match the design-time configuration
For i = 0 To 2
    Set objCurve = objCtrl.GetTrend(i)
    Select Case i
        Case 0
            objCurve.TrendTagName = strPrefix & "\OilTemp"
            objCurve.TrendName    = "Oil Temperature"
            objCurve.TrendColor   = RGB(255, 0, 0)
            objCurve.TrendVisible = True
        Case 1
            objCurve.TrendTagName = strPrefix & "\Pressure"
            objCurve.TrendName    = "Pressure"
            objCurve.TrendColor   = RGB(0, 200, 0)
            objCurve.TrendVisible = True
        Case 2
            objCurve.TrendTagName = strPrefix & "\FlowRate"
            objCurve.TrendName    = "Flow Rate"
            objCurve.TrendColor   = RGB(0, 0, 255)
            objCurve.TrendVisible = False   ' Hidden by default; toggled later
    End Select
Next

6.3 React to Prefix Changes

If the operator changes the active line from the HMI, fire a tag-prefix change event (e.g., on a button click) that re-runs the configuration script. The control rebuilds its internal curve table on each assignment, so the script is idempotent and safe to call repeatedly.

' Sub called from a button's Click event
Sub OnPrefixChanged
    Dim strNewPrefix
    strNewPrefix = SmartTags("ActiveTagPrefix")

    Dim objCtrl
    Set objCtrl = ScreenItems.Item("Control1")

    objCtrl.GetTrend(0).TrendTagName = strNewPrefix & "\OilTemp"
    objCtrl.GetTrend(1).TrendTagName = strNewPrefix & "\Pressure"
    objCtrl.GetTrend(2).TrendTagName = strNewPrefix & "\FlowRate"
End Sub

6.4 Use the Built-In Toolbar for Show/Hide

WinCC OnlineTrendControl exposes a default toolbar (the "Select Trends" icon) that calls a configurable event handler. The OnToolbarButtonClicked event receives the button ID; the application can then show a popup that toggles per-curve visibility:

' Handle toolbar button click — show/hide curve 2
Sub OnToolbarButtonClicked(ByVal item, ByVal buttonId)
    If buttonId = 5 Then  ' Example: assume button 5 is "Select Trends"
        Dim objCurve
        Set objCurve = ScreenItems.Item("Control1").GetTrend(2)
        objCurve.TrendVisible = Not objCurve.TrendVisible
    End If
End Sub

The button-ID mapping is documented in the same scripting manual (A5E50503017-AA), section 1.14.4. Note that some IDs are reserved by the runtime and must not be reassigned.

7. Complete Parameter Reference

The following table lists the most commonly used properties of the OnlineTrendControl and its GetTrend() curve objects. All read/write properties are accessible from VBS; read-only properties are listed for completeness.

Object Property Type Access Description
Control TrendCount Long Read Number of configured curves (mirrors the design-time count)
Control TimeAxis Object Read Returns the time-axis object; use .BeginTime, .EndTime, .TimeRange to set the visible window
Control ValueAxis Object Read Returns the value-axis object; controls scaling, autoscale, limits
Control TrendWindow Object Read Returns the trend-window object (the plot area)
Control Title String Read/Write Title displayed at the top of the control
Curve Index Long Read Returns the index of the curve (0-based)
Curve TrendTagName String Read/Write Full archive path or PLC-qualified tag name
Curve TrendName String Read/Write Display name shown in the legend
Curve TrendColor Long Read/Write Curve color in BGR format (WinCC color picker uses BGR, not RGB)
Curve TrendVisible Boolean Read/Write Show/hide the curve in the plot
Curve TrendLineType Long Read/Write 0 = solid, 1 = dashed, 2 = dotted, 3 = dash-dot
Curve TrendLineWidth Long Read/Write Pixel width, 1 to 8
Curve ValueAxis Object Read Per-curve value-axis assignment
Curve Provider Long Read/Write Data provider: 0 = archive, 1 = online tag (live)
Color format warning: The RGB() VBScript function returns a value in standard RGB order (0xRRGGBB), but WinCC stores the value internally as BGR (0xBBGGRR). When you assign objCurve.TrendColor = RGB(255, 0, 0) expecting pure red, the control interprets the bytes as BGR and displays blue. The two common workarounds are: (1) use the hexadecimal BGR constant directly: objCurve.TrendColor = &H0000FF for red, or (2) use a helper that swaps the bytes. Test with a known color before committing to the design.

8. Common Errors and Field-Recovered Fixes

Error / Symptom Likely Cause Resolution
"Object required: '[undefined]'" on Set obj = ScreenItems.Item("Control1") Missing Set keyword (VBS treats it as a value assignment and tries to invoke a default property) Always use Set when assigning an object reference: Set objCtrl = ScreenItems.Item("Control1")
"Subscript out of range" on GetTrend(5) Index ≥ TrendCount Match the loop bound to the design-time count; do not exceed the configured number of curves
Trend area is blank, no error message Tag name contains an unresolved prefix placeholder (e.g., the literal text {prefix} ag) Apply Solution 2 to construct the full tag name in VBS
Trend shows old/stale data after a prefix change The VBS script set the TrendTagName but did not refresh the control Force a refresh by toggling TrendVisible twice, or reassign the time-axis range
Wrong color (red appears as blue and vice versa) RGB/BGR byte order mismatch Use &HBBGGRR hex literal; example: red = &H0000FF
Only the first curve is visible after VBS assignment The TrendTagName property in the configuration dialog overrides runtime assignments because the curve was set to "fixed" (object name source) Change the trend source from "Object name" to "Tag name" in the configuration dialog, or uncheck the "Lock object name" option
Runtime error: "Archive not found" The archive name in TrendTagName does not match the configured tag-logging archive Open the tag-logging editor in TIA Portal and copy the archive name exactly as shown
VBS script does not run on the panel VBScript is not enabled in the HMI device runtime settings HMI device → Runtime settings → Scripts → check "Activate VBScript"

9. Verification and Commissioning Steps

After applying either solution, perform the following checks before sign-off:

  1. Compile and download the project to the target. Watch the TIA Portal output panel for warnings related to the trend control.
  2. Open the screen that contains the trend. Verify the trend control renders axes and a time grid.
  3. Trigger the VBS script (e.g., the Open event of the screen). Use a temporary HMIRuntime.Trace call to log each TrendTagName assignment to the diagnostic trace buffer.
  4. Open the configuration dialog of the trend control at runtime (right-click → Configuration). Confirm the Tag name column shows the resolved full path, not a placeholder.
  5. Toggle the curve visibility via the built-in Select Trends toolbar. Each curve should appear/disappear without disturbing the others.
  6. Change the prefix at runtime (e.g., select a different production line from a dropdown). The trend should repopulate with the new tag within one polling cycle.
  7. Cross-check the tag values in the trend against the live PLC value (use a watch table or an HMI tag display) to confirm the prefix substitution is correct.
  8. Disconnect the PLC and confirm the trend shows "No connection" or grayed axes rather than a runtime error. This is the correct behavior for a valid tag with a missing PLC.

10. Best Practices for Production Code

  • Centralize the prefix string in a single HMI tag (e.g., ActiveTagPrefix) so the entire application reads the same value. Avoid hard-coding the prefix in multiple places.
  • Use a wrapper sub that takes the control name, curve index, and tag suffix as parameters. This eliminates the "Not DRY" (Don't Repeat Yourself) criticism of duplicating the prefix concatenation in every script.
  • Validate the tag name before assigning it: check for empty prefix, leading/trailing backslashes, and illegal characters. Assigning a malformed string silently fails — the trend simply shows no data.
  • Document the tag-logging archive name in the project notes. Archive names are case-sensitive on Comfort Panels and RT Advanced; a mismatch is one of the most common commissioning delays.
  • Test with picture windows if you intend to use the same trend screen inside multiple picture windows. The trend control's data sources are evaluated at the screen level, not the picture-window level.
  • Limit curve count to 8 on Comfort Panels — higher counts degrade redraw performance. RT Professional handles more, but 8–12 is a practical ceiling for readability.

11. Differences from Classic WinCC V7

Engineers maintaining mixed fleets (WinCC V7 panels and TIA Portal panels) should note the following differences:

Aspect WinCC V7 / Classic TIA Portal (V15.1+)
Control class name CCAxOnlineTrendControl.OnlineTrendControl.1 HMIOnlineTrendControl (wrapped ActiveX)
GetTrend() method Yes, same signature Yes, same signature
Picture-window prefix support Not supported on the trend control Not supported on the trend control
ANSI-C interface Available (GetTrendProp, SetTrendProp) Deprecated in favor of VBS
Tag-logging archive path syntax ArchiveName::Tag (double colon) ArchiveName\Tag (single backslash, but TIA portal accepts both)
VBA (configuration-time scripting) Available in the Graphics Designer Not available — use VBS in the screen events
Migration note: When porting a WinCC V7 project to TIA Portal, the most common broken feature is the trend control inside a picture window with a runtime prefix. The migration tool imports the project but does not rewrite the TrendTagName properties. Manual verification is required for every trend control that was inside a picture window in the source project.

12. Reference: Siemens Official Documentation

Can the picture-window TAG_PREFIX be made to work with the trend control?

No. The TIA Portal V20 VBS object model documentation explicitly lists picture-window TagPrefix as a property that is applied at compile/runtime to all tag-evaluable properties of the embedded screen. The OnlineTrendControl registers its TrendTagName as opaque (because it accepts archive paths, connection-qualified paths, and formula references), so the prefix substitution engine skips it. The official workaround is to either embed the prefix manually in each curve's TrendTagName at design time, or to set TrendTagName from VBS at runtime using a string built from the active prefix.

What is the correct path syntax for TrendTagName with a tag-logging archive?

Use the archive name followed by a single backslash and the tag name exactly as configured in the tag-logging editor. Example: "TAGGLOGGING_ARCHIVE\trendtag1". The archive name is case-sensitive on Comfort Panels and RT Advanced. For a live PLC tag, use the connection-qualified path "S7-1500S/PLC_1::DB1.HMI_Data.OilTemp".

How do I hide or show a single trend curve via VBS?

Use the TrendVisible property of the curve object returned by GetTrend(Index): ScreenItems.Item("Control1").GetTrend(2).TrendVisible = False. The 0-based index must be less than the number of curves configured in the design-time dialog.

Why does my VBS assignment Set obj = ScreenItems.Item("Control1") fail with "Expected = "?

VBScript requires the Set keyword for object reference assignments. If you write obj = ScreenItems.Item("Control1") without Set, the runtime tries to call a default property of the right-hand side (a common VBS quirk) and reports a syntax error. The correct form is Set objCtrl = ScreenItems.Item("Control1").

Does the WinCC Online Trend Control support the same prefix syntax in WinCC V7 (classic)?

No. The classic ActiveX CCAxOnlineTrendControl in WinCC V7 had the same limitation: picture-window tag prefixes were ignored for TrendTagName properties. The legacy SetPropChar / GetPropChar ANSI-C interface did not provide a prefix-substitution mechanism either. The TIA Portal VBS-based interface inherits the same behavior; it is by design, not a regression.

Back to blog