Configuring VBScript Timers in WinCC Flexible HMI Panels

David Krause10 min read
SiemensTutorial / How-toWinCC
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 VBScript Timers in WinCC Flexible HMI Panels

Siemens WinCC Flexible is the legacy HMI configuration environment that was used for SIMATIC panels prior to the TIA Portal-based WinCC Comfort/Advanced and WinCC Unified/Professional. Engineers still encounter brownfield installations running WinCC Flexible 2005, 2007, 2008, or 2008 SP3 on operator panels, and the question of which scripting language the runtime supports remains a frequent point of confusion. This reference explains the C-Script versus VBScript support matrix, shows working VBScript timer code, documents the affected runtime versions, and maps a migration path to the current RT Professional environment.

1. WinCC Flexible Overview and Scripting Architecture

WinCC Flexible configures the SIMATIC HMI panel families (K/TP 170/270/370, MP 270/370, OP 170/270/370, OP 73/77, TP 170/177/270/277/370, MP 177/277/377, Comfort Panels via early migrations, C7-635/636, and WinAC MP). Each panel runtime executes a stripped-down version of the configuration, and the available scripting engine depends on the runtime build rather than the configuration tool version.

Two scripting languages are relevant:

  • C-Script — syntax-compatible subset of ANSI C, exposed as project functions and standard functions. Available on practically every WinCC Flexible panel runtime.
  • VBScript (VBS) — Microsoft Visual Basic Scripting Edition 5.x, hosted through the Windows CE / Windows XP Embedded scripting engine. Available on a narrower subset of panel runtimes that bundle the VBS interpreter.
The configuration tool (WinCC Flexible ES) can author both languages, but the panel runtime determines which interpreter is actually deployed. Authoring a VBScript on a runtime that lacks the VBS engine produces a load error or silent no-op at panel start-up.

2. C-Script vs VBScript: Version and Panel Support Matrix

Runtime / Panel Family C-Script VBScript Notes
WinCC (PC RT) 6.0 and later Yes Yes (added in v6) VBS introduced as a parallel engine in WinCC v6.0
WinCC (PC RT) 5.x and earlier Yes No Pre-v6 PC runtime shipped only the C interpreter
WinCC Flexible 2005 panel runtimes (OP 77B, TP 170A/B, OP 170, MP 270B basic) Yes No (most OP/TP 170/270 basic class) Use C-Script for these targets
WinCC Flexible 2007/2008 panel runtimes (TP 177B/177C, MP 277, OP 277, MP 377, panels based on Windows CE 5.0/6.0) Yes Conditional — depends on panel firmware Check the panel's "Properties > General > Runtime Version" before authoring VBS
WinCC Comfort / Advanced (TIA Portal, panels >= V11) Yes Yes Both languages fully supported
WinCC RT Professional (TIA Portal, PC runtime, V14+) Yes (via C-VBS dual interface) Yes Reference: Integrating local VB scripts (RT Professional)

The original poster was using "WinCC 2005" (a WinCC Flexible build), and explicitly noted that the right-click context menu of the script editor did not show a "C Script" option. This is a strong indicator that the project was opened on a newer configuration host (or the project was migrated) and the panel target's runtime profile is the limiting factor — not the ES. The decision path is always: confirm the panel's runtime image supports VBS, then author VBS; otherwise use C-Script.

3. When VBScript Is the Right Choice on WinCC Flexible

VBScript offers tighter integration with HMI tag objects, simplified string handling, and direct use of the VBScript DateAdd, DateDiff, Timer, and FormatDateTime functions. For projects dominated by string formatting, recipe CSV import/export, logging rotation, and shift/time-of-day logic, VBS reduces the development effort substantially compared to C-Script, where the same string work must be done through sysstrcmp, sysstrncpy, and ASCII buffers.

C-Script still wins for:

  • Bit-level work and high-frequency cyclic tasks (< 100 ms)
  • Code that must run on basic OP/TP 170-class panels without VBS
  • Code that depends on tightly-scoped local scope (C locals are stack-allocated; VBS uses Variant for everything)

4. VBScript Timer Implementation Reference

A "timer script" in WinCC Flexible parlance is a VBS or C function scheduled to execute on a fixed cycle. There is no explicit SetTimeout in the runtime API; instead, scheduling is performed through the scheduler and the function is invoked every N seconds. The pattern below shows a cyclic timer used to drive a 1-Hz status indicator and to roll a shift log tag.

4.1 Scheduler Configuration

In the WinCC Flexible project tree, navigate to Schedules > Schedules, create a new schedule, and attach the VBS function. The schedule interval must be a multiple of 100 ms; the smallest supported on most panels is 250 ms.

Schedule parameter Typical value Constraint
Trigger Cyclic Triggered-by-event schedulers also work for digital inputs
Cycle (ms) 1000 Minimum 100 ms (100 on Comfort Panels); panel-dependent
Function Tick_1s Must be a project or standard function in the VBS pool
Scope Global Tag-prefix scope is also permitted

4.2 VBScript Tick Function

'------------------------------------------------------------------
' Function:   Tick_1s
' Trigger:    Schedule, 1 s cyclic
' Purpose:    Heartbeat, blink tag, and shift log rollover
'------------------------------------------------------------------
Sub Tick_1s()
    Dim hb          ' heartbeat pulse
    Dim blink       ' 0/1 toggle for IO field visibility
    Dim nowH, nowM, nowS
    Dim shiftTag

    ' Read HMI tags (Sm@rtClient / area pointers must be configured)
    hb    = HMIRuntime.Tags("HMI_Heartbeat").Read
    blink = HMIRuntime.Tags("HMI_Blink").Read

    ' Toggle blink at 0.5 Hz (every other call)
    If blink = 0 Then
        HMIRuntime.Tags("HMI_Blink").Write 1
    Else
        HMIRuntime.Tags("HMI_Blink").Write 0
    End If

    ' Drive heartbeat high then low; produces a 1-Hz pulse for PLC
    If (hb = 0) Then
        HMIRuntime.Tags("HMI_Heartbeat").Write 1
    Else
        HMIRuntime.Tags("HMI_Heartbeat").Write 0
    End If

    ' Shift rollover at 06:00:00 — log entry to recipe/text-tag
    nowH = Hour(Now)
    nowM = Minute(Now)
    nowS = Second(Now)

    If (nowH = 6) And (nowM = 0) And (nowS < 5) Then
        shiftTag = HMIRuntime.Tags("HMI_LastShiftLog").Read
        HMIRuntime.Tags("HMI_LastShiftLog").Write _
            FormatDateTime(Now, vbShortDate) & " 06:00 - shift change"
    End If
End Sub

Key runtime API elements used above:

  • HMIRuntime.Tags("<Name>") — returns a tag object. Requires the tag to exist in the project tag table; otherwise a runtime error is thrown.
  • .Read / .Write <value> — synchronous read/write.
  • VBS built-in Now, Hour, Minute, Second, FormatDateTime.
On Windows CE / Windows Embedded Compact panel runtimes, the VBS engine implements VBScript 5.x minus the file-system and shell objects. Calls to Scripting.FileSystemObject and WScript.Shell are not available. Use the WinCC Flex-specific HMIRuntime object or the SmartService / SmartClient APIs for file operations.

4.3 C-Script Equivalent (for panels without VBS)

// Function: Tick_1s_C
// Trigger:  Schedule, 1 s cyclic
// Purpose:  Heartbeat for VBS-incapable panels (TP 170A, OP 77B)

#include "apdefap.h"
void Tick_1s_C(void)
{
    DWORD hb, blink;
    static int toggle = 0;

    hb    = GetTagWord("HMI_Heartbeat");
    blink = GetTagWord("HMI_Blink");

    blink = (blink == 0) ? 1 : 0;
    SetTagWord("HMI_Blink", (WORD)blink);

    hb = (hb == 0) ? 1 : 0;
    SetTagWord("HMI_Heartbeat", (WORD)hb);

    if (toggle == 0)
        toggle = 1;
    else
        toggle = 0;
}

The C-Script API uses GetTagXXX / SetTagXXX where XXX is Bit, Byte, Word, DWord, Char, Float, or Double. These calls are non-blocking and safe to invoke from a schedule.

5. Common Configuration Pitfalls

Symptom Likely cause Resolution
Schedule fires but no tag changes Tag is not in the project tag table, or connection interrupted Open "Connections" and verify the PLC link is "Connected"; verify tag spelling with case sensitivity
"Object required: HMIRuntime" runtime alarm Function executed outside the HMI runtime (e.g., test in ES) Deploy to a panel; the ES does not instantiate HMIRuntime
C-Script option missing in right-click menu Project was migrated to a newer ES, or the function was originally authored as VBS Right-click the function > "Properties" and confirm language; re-author as C-Script if required
VBS function never fires on OP/TP 170A Panel firmware lacks VBS interpreter Replace with C-Script; verify against panel image (Image Update via ProSave)
Schedule interval clamped to 1000 ms Panel runtime is 250 ms-minimum (e.g., OP 77B) Reduce scheduling density or migrate to a Comfort/PC runtime
Tag write rejected, error 0x80004005 Tag is configured read-only or area pointer is external Open tag properties > "Acquisition/Display" > enable write

6. Diagnosing the Right-Click "C Script" Menu Issue

  1. The function being edited was originally authored in VBS. C-Script and VBS are mutually exclusive per function; the function's Properties > General > Language field controls which menu options appear.
  2. The ES host is WinCC Comfort/Advanced on TIA Portal. In TIA Portal, the script editor's language is selected when the function is created; the right-click context menu is replaced by a property sheet.
  3. The target panel runtime was filtered by the configuration tool. The ES disables languages that are not in the panel's runtime profile.

To force a C-Script function, choose Scripts > New > C Function from the project tree — the language is locked at creation.

7. Migration Path to TIA Portal / RT Professional

WinCC Flexible ES is end-of-life and is not maintained for current hardware. For new panels or panel refreshes, projects should be migrated to TIA Portal WinCC Comfort/Advanced or to WinCC RT Professional. Migration tools in the TIA Portal import WinCC Flexible projects and convert:

  • C-Script functions → C-Script functions (high fidelity, > 95% pass-through)
  • VBScript functions → VBScript functions (90% pass-through; some COM objects must be re-mapped)
  • Schedules → Schedules (cycle granularity preserved)
  • Tag table → Tag table (PLC and HMI tag names retained)

For PC-based operator stations, RT Professional is the successor platform. Local VB scripts in RT Professional are authored under Project > Scripts > VB > Local and integrate with the system functions through the function list. Per Siemens documentation, the function list can be converted into a local script and edited inline. Reference: Integrating local VB scripts (RT Professional).

For panel-based Comfort targets, VBS remains a first-class language alongside C-Script. For Unified Comfort Panels (MTP/ET 200SP HMI), the script model is JavaScript (ECMAScript 5.1+) and existing VBS must be rewritten.

8. Verification Procedure After Authoring a VBScript Timer

  1. Compile the project. Watch for warnings tagged "VBS function <name>: implicit Variant conversion" — these are usually benign but can mask logic errors in arithmetic.
  2. Simulate with the WinCC Flexible runtime simulator. The simulator runs against the ES and exercises both VBS and C-Script.
  3. Add a temporary HMIRuntime.Trace call (PC runtime only) or write a debug string to a visible text tag to confirm the schedule is firing at the correct cadence.
  4. Deploy to the target panel. On the panel, navigate to Start Center > Control Panel > System > Information > Version and confirm the runtime image includes the VBS option. On a CE 5.0/6.0 panel, this is shown as a feature bit in the panel's .img.
  5. Force a tag write from the PLC and confirm the script reacts within one scheduling cycle.

9. Field-Commissioning Checklist

  • Confirm panel firmware revision >= the WinCC Flexible ES version's minimum. Mismatches cause silent feature loss, including VBS.
  • Confirm PLC connection name in the HMI tags matches the configured connection; case-sensitive.
  • For schedules firing below 250 ms, verify the panel CPU load in the diagnostic page; > 80% load will drop schedule ticks.
  • Always provide a "manual override" tag so the schedule can be suspended during commissioning.
  • Export the runtime trace to a USB stick or SD card and include it in the as-built documentation.

10. Frequently Asked Questions

Does WinCC Flexible 2005 support VBScript?

No. The WinCC Flexible 2005 panel runtimes for OP/TP 170-class and basic MP 270B panels ship only the C-Script interpreter. VBScript support requires WinCC Flexible 2007 or later, and the panel firmware must be a build that includes the VBS engine. PC-based WinCC runtime added VBS support in WinCC v6.

Why does the right-click menu in the script editor not show a C Script option?

The function's language is locked at creation. Once a function is authored as VBS, only the VBS-related menu items appear. To use C-Script, create a new function and explicitly select "C Function" from the Scripts > New menu. The editor language is then fixed.

What is the minimum schedule cycle for a VBScript timer on a Comfort Panel?

The minimum cycle is 100 ms on Comfort Panels and on most Windows CE 5.0/6.0 panels from 2007 onward. On older OP/TP 170-class panels the minimum is 250 ms, and the configuration tool clamps the value to the supported range automatically.

Can I use FileSystemObject in a VBScript on a WinCC Flexible panel?

No. The Windows CE / Windows Embedded Compact runtime strips the file-system and shell object libraries. Use the WinCC Flexible SmartService / SmartClient API or the recipe view for file I/O, or migrate to RT Professional where FSO is supported on the PC runtime.

How do I migrate a WinCC Flexible VBScript timer to TIA Portal?

Use the TIA Portal migration tool to import the .hmi project. C-Script functions migrate with high fidelity; VBScript functions migrate with about 90% of code passing through, but COM objects and missing methods must be re-mapped. For Unified Comfort Panels, VBS must be rewritten in JavaScript (ECMAScript 5.1+). For PC-based operator stations, target WinCC RT Professional and reference the integrating local VB scripts documentation for the modern VBS authoring workflow.

Back to blog