OK/Cancel Confirmation Dialogs in WinCC Flexible Runtime

David Krause14 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

1. Problem Statement and Runtime Context

Operator-driven HMI projects frequently require explicit operator confirmation before a write action is committed to a PLC tag. In a WinCC Flexible Runtime project, a typical requirement is to present a two-button confirmation prompt (OK / Cancel) and only execute a SetBit on the target tag when the operator confirms. The same dialog must also offer a clean abort path so a stray tap or click does not change process state.

WinCC Flexible Runtime (the embedded / PC Runtime of the WinCC Flexible engineering suite) does not expose a native MessageBox with OK and Cancel dialog object the way WinCC SCADA or the WinCC Professional (TIA Portal) editor does. The dialog must therefore be constructed from primitives that are part of the WinCC Flexible screen library, or it must be implemented in VBScript using a Windows scripting host call. Both routes are valid; the choice depends on how many confirmation points exist, the runtime target (Windows panel vs. PC), and the multilingual / style requirements of the project.

This reference covers both implementation paths, compares them, and provides a reusable VBScript wrapper that scales to a large number of confirmation points without duplicating screen objects.

2. WinCC Flexible Runtime vs. WinCC SCADA Comparison

Before committing to a design, confirm the runtime target. The capabilities of the two products are not identical, and the dialog implementation depends on which one is in use.

Capability WinCC Flexible Runtime WinCC SCADA (WinCC V7 / Professional)
Built-in MessageBox with OK / Cancel / Yes-No / Abort-Retry-Ignore buttons Not directly available as a system function on screen objects Available via ShowMessageBox / alarm logging system functions
Pop-up image (modal layer) Supported — use a template image with Activate / Deactivate events Supported
VBScript runtime support Yes (SmartTags object, SetBit / ResetBit / InvertBit) Yes (HMIRuntime object)
External ActiveX / WSH calls (e.g. WScript.Shell) Yes on PC Runtime; limited or unavailable on Windows CE Panel targets Yes
Configuration tool WinCC Flexible 2008 SP5 (or earlier SP) / Migration to TIA Portal WinCC V7.x or WinCC Professional in TIA Portal
Typical target hardware SIMATIC Panel, PC Runtime, WinCC flexible RT on Windows WinCC Station (OS server / client)

Key takeaway: in a WinCC Flexible Runtime project, both a screen-engineering approach and a VBScript approach are viable; the SCADA-style native MessageBox system function is not.

3. Prerequisites and Engineering Environment

  • WinCC Flexible 2008 SP5 engineering station with a valid license (or later SP level that matches the project).
  • A configured WinCC Flexible project with at least one screen and at least one HMI or PLC tag that can be set / reset (Boolean tag recommended).
  • Defined connection from the HMI device to the PLC (MPI / PROFIBUS / PROFINET / Ethernet) and a working tag pointer.
  • For the VBScript path: a Windows-based runtime target that hosts the Windows Script Host (PC Runtime, WinCC flexible RT on Windows). Windows CE / WinCC flexible RT on CE panels do not provide WScript.Shell by default; the image-based path is required there.
  • User authorization configured for the Set/Reset button if process safety requires it (WinCC Flexible user administration).

4. Approach A — Pop-Up Image with OK and Cancel Buttons

This is the only universal path across all WinCC Flexible Runtime targets, including CE-based panels. Two screen layers are used: a permanent base layer with the operator button, and a pop-up layer with the confirmation prompt that is activated on demand.

4.1 Create the pop-up images

  1. In the WinCC Flexible project tree, expand Screens > [Project name] > Screen_1.
  2. Create a new screen named PopUp_Confirm_Set. Add a static text field with the prompt (e.g. "Set bit 'Tag_name'?"). Add two buttons: btn_OK and btn_Cancel.
  3. Repeat for PopUp_Confirm_Reset with a different prompt.
  4. Place the pop-up screens on a higher layer index than the calling screen so they draw on top.

4.2 Wire the OK button to the Set/Reset function

  1. Select btn_OK on the Set pop-up. Under Events > Click configure the function SetBit with the tag name (e.g. Tag_name).
  2. On the Reset pop-up, configure ResetBit on the btn_OK click event.
  3. On btn_Cancel of both pop-ups, configure the function ClearScreen or ActivateScreen with the original screen name, or use StopRuntime on the pop-up image's OnCleared event to dismiss the pop-up.

4.3 Trigger the pop-up from the calling screen

  1. On the calling screen, add a Set button and a Reset button.
  2. On the Set button Click event, configure ActivateScreen with the screen name PopUp_Confirm_Set and the option to open as a pop-up (change screen mode = pop-up).
  3. Repeat for the Reset button pointing to PopUp_Confirm_Reset.

This approach is verbose when the project contains many confirmation points: every tag that needs an OK/Cancel gate requires its own pair of pop-up screens. That is why the VBScript path is preferred for projects with more than a handful of confirmation prompts.

5. Approach B — VBScript WScript.Shell.Popup

WinCC Flexible supports VBScript on every scriptable event of a screen object. The script has access to the SmartTags dictionary, to the standard VBScript library, and (on a Windows-based runtime) to COM automation. A confirmation dialog can be displayed by creating a WScript.Shell instance and calling its Popup method.

5.1 Reference script

The following script is attached to the Click event of a single button. It prompts the operator, sets the tag if OK is pressed, and resets it if Cancel is pressed.

' WinCC Flexible VBScript - OK/Cancel confirmation on a single button
' Event: Click of button "btn_Confirm_Toggle"

Dim WSHShell, nPop
Set WSHShell = CreateObject("WScript.Shell")

nPop = WSHShell.Popup("Do you want to change the Tag?", , "Operator confirmation", 1)

If nPop = 1 Then
    ' OK pressed
    SmartTags("Tag_name") = 1          ' equivalent to SetBit
Else
    ' Cancel pressed, timeout, or window closed
    SmartTags("Tag_name") = 0          ' equivalent to ResetBit
End If

Set WSHShell = Nothing

5.2 WScript.Shell.Popup parameters

Argument Type Description
Text String Message displayed in the dialog
SecondsToWait Integer Timeout in seconds; 0 = wait indefinitely
Title String Title bar of the dialog
Type Integer Combination of button and icon constants (see table below)

5.3 Button / icon type constants

Type value Buttons shown Icon
0 OK —
1 OK, Cancel —
2 Abort, Retry, Ignore —
3 Yes, No, Cancel —
4 Yes, No —
16 — Critical (X)
32 — Warning ( ! )
48 — Information ( i )
64 — Question ( ? )

To combine buttons and an icon, sum the two values. For example, 1 + 32 yields an OK / Cancel dialog with a warning icon. The type value used in the source snippet is 1 (OK / Cancel, no icon).

5.4 Return value mapping

Return Meaning Typical handling
1 OK button pressed Set the tag
2 Cancel button pressed Abort the action
3 Abort Abort the action
4 Retry Retry the dialog
5 Ignore Abort the action
6 Yes Proceed with the action
7 No Abort the action
-1 Timeout (no user input) Treat as Cancel

6. Approach C — Reusable VBScript Function Library

For projects with many confirmation points, the cleanest pattern is to declare a single helper procedure (a "script library") and call it from every button that needs confirmation. In WinCC Flexible, a procedure is declared once in a project-wide VBScript module and reused across screens.

6.1 Project-wide script module

' --- Project VBScript module: ConfirmTag ---
' Reusable OK / Cancel confirmation wrapper for any Boolean tag.

Sub ConfirmTag(sTagName, sPrompt, sTitle)
    Dim WSHShell, nPop
    On Error Resume Next
    Set WSHShell = CreateObject("WScript.Shell")
    If Err.Number <> 0 Then
        ' WSH not available on this runtime (e.g. CE Panel).
        ' Fall back to direct set; protect with authorization at the screen level.
        SmartTags(sTagName) = 1
        Exit Sub
    End If
    On Error Goto 0

    nPop = WSHShell.Popup(sPrompt, 0, sTitle, 33)   ' 1 (OK/Cancel) + 32 (warning icon)

    Select Case nPop
        Case 1          ' OK
            SmartTags(sTagName) = 1
        Case Else       ' 2 = Cancel, -1 = timeout
            SmartTags(sTagName) = 0
    End Select

    Set WSHShell = Nothing
End Sub

Sub ConfirmResetTag(sTagName, sPrompt, sTitle)
    Dim WSHShell, nPop
    On Error Resume Next
    Set WSHShell = CreateObject("WScript.Shell")
    If Err.Number <> 0 Then
        SmartTags(sTagName) = 0
        Exit Sub
    End If
    On Error Goto 0

    nPop = WSHShell.Popup(sPrompt, 0, sTitle, 33)

    Select Case nPop
        Case 1
            SmartTags(sTagName) = 0
        Case Else
            SmartTags(sTagName) = 0   ' No change requested
    End Select

    Set WSHShell = Nothing
End Sub

6.2 Calling the helper from a button

' Button "btn_Set_Heater" — Click event
ConfirmTag "Heater_Run", "Switch the heater ON?", "Operator confirmation"
' Button "btn_Reset_Alarm" — Click event
ConfirmResetTag "Alarm_Ack", "Acknowledge alarm 1?", "Operator confirmation"

6.3 Why a library scales better

Replacing each pop-up screen pair with a one-line call removes the engineering overhead of duplicating graphics, button objects, and event handlers. Adding a new confirmation point is a single line of VBScript on the new button.

7. HMI Tag Configuration and Bit Operations

The confirmation scripts above use the SmartTags dictionary directly. The equivalent system functions available from the WinCC Flexible function list are:

Operation System function VBScript equivalent
Set bit to 1 SetBit SmartTags("Tag") = 1
Reset bit to 0 ResetBit SmartTags("Tag") = 0
Invert bit InvertBit SmartTags("Tag") = 1 - SmartTags("Tag")

When the target tag is a PLC tag (not an internal HMI tag), the HMI must be configured with a valid connection to the controller and the tag must be linked to the appropriate PLC address. Confirm that the tag acquisition mode is set to Cyclic continuous if you need to see the result on the screen immediately after the write.

8. Microsoft MsgBox Function Reference

The WScript.Shell.Popup method returns the same integer codes that the VBA MsgBox function uses, so the logic that interprets the return value is identical. For projects where the developer chooses to invoke MsgBox directly (e.g. from an HMI action or a WinCC OLE DB interface), the canonical reference for the button / icon type constants and the return codes is the Microsoft documentation.

See: MsgBox function — Microsoft Support.

Important properties from that reference that apply to confirmation dialogs:

  • If the dialog box displays a Cancel button, pressing the Esc key has the same effect as selecting Cancel. Operator touch panels should therefore treat an Esc event the same as a Cancel return code.
  • If the dialog box contains a Help button, context-sensitive Help is provided. The popup built with WScript.Shell.Popup does not expose a Help button (use a button type of 0–5 only); do not add a Help icon combination.
  • The first button is the default; the timeout must be considered when designing touch-driven operation so an unattended screen does not silently trigger a write.

9. Performance and UX Trade-offs

Criterion Pop-up image (Approach A) VBScript WSH (Approach B/C)
Reusability across many tags Low — one pop-up per tag set High — single helper handles every tag
Style / branding control Full — designer controls the look Limited — uses native Windows dialog
Multilingual text Native — language switching in WinCC Flexible Manual — must pass localized strings or read from a text tag
Runtime target compatibility All panels and PC Runtime Windows-based runtime only
Touch / finger operation on 4" panels Native button objects sized to fit Small OK / Cancel buttons in the OS dialog can be hard to hit
Behavior under heavy CPU load Consistent — drawn by WinCC engine OS dialog can be delayed or hidden behind full-screen Runtime
User authorization integration Trivial — apply on the calling button Possible — check current user inside the VBScript

For Windows-CE based panels (for example SIMATIC Comfort Panels older than the TIA Portal generation, or WinCC flexible RT running on CE), only Approach A or a VBScript path that does not depend on WScript.Shell will work.

10. Best Practices and Common Pitfalls

Always release the COM object. The pattern Set WSHShell = Nothing at the end of the script is not decorative. In long-running Runtime sessions, leaked WScript.Shell instances accumulate and eventually lock the process. Pair every CreateObject with a Set ... = Nothing.
  • Decide the action on Cancel explicitly. In a toggle-style confirmation (e.g. one button, two outcomes) the Cancel return code must produce a defined tag state. Do not leave the bit untouched unless that is the documented behavior, and document the choice in the operator manual.
  • Treat timeout as Cancel. A Popup with a non-zero SecondsToWait returns -1 on timeout. Make sure the Select Case (or If) handles -1 the same as Cancel.
  • Use authorization. For set/reset operations on process-critical tags, protect the calling button with a user group (e.g. Operators or Maintenance) under Properties > Security in WinCC Flexible.
  • Localize prompts. If the project supports multiple languages, store the confirmation text in a text list (WinCC Flexible Text and Graphic Lists) and read the localized string into the VBScript at runtime with SmartTags("ConfirmPrompt" + HmiRuntime.Language).
  • Avoid modal dialogs during alarm acknowledgement. Displaying a WSH popup while an active alarm is being acknowledged can hide the alarm line. Trigger the popup from a dedicated "acknowledge with confirmation" screen, not from an alarm view event.
  • Do not embed passwords or write-protection logic in the prompt. The dialog is visible to anyone with access to the screen. Use WinCC Flexible user administration, not the popup, to gate the action.

11. Verification and Commissioning

  1. In the WinCC Flexible ES, compile the project (Project > Compiler > All) and start the Runtime simulator.
  2. Click the configured button. The popup or pop-up image must appear with both OK and Cancel buttons.
  3. Press Cancel. Verify in the tag monitor or in the PLC (VAT / watch table) that the tag value did not change.
  4. Click the button again, press OK. Verify the tag has the expected value (1 for Set, 0 for Reset).
  5. With a second operator (or by switching user), confirm the user authorization actually blocks unauthorized users from invoking the script.
  6. Stop and restart the Runtime. Confirm the dialog still appears; this validates that the COM object is correctly released and re-created on session restart.
  7. On a Windows-CE based panel target (if used), confirm the VBScript path falls back gracefully — either an error is logged and the tag is set with a warning, or the project switches to the image-based path. Do not deploy the WSH-based version on a panel that does not support it.

12. Troubleshooting Matrix

Symptom Likely cause Remediation
Popup does not appear when the button is pressed Runtime target is Windows CE / Panel RT without WSH; CreateObject("WScript.Shell") fails silently Switch to Approach A (pop-up image), or use the VBScript fallback that sets the tag and logs a diagnostic
Popup appears but tag value does not change Tag is a PLC tag with an unconfigured / disconnected HMI-PLC connection Open Connections in WinCC Flexible, verify the connection is green, re-link the tag, recompile
Tag is set when Cancel is pressed Comparison uses the wrong return code; Cancel returns 2, OK returns 1 Use Select Case nPop with explicit Case 1 for OK and a default for all other return values
Runtime slows down after several confirmations COM object not released; Set WSHShell = Nothing missing Add the release line at the end of every script; restart Runtime to confirm recovery
Esc key closes the dialog with the wrong branch Script treats Esc as OK; the reference behavior is that Esc is the same as Cancel Map Esc (return value of Cancel) to the Cancel branch; verify with Microsoft MsgBox reference
Popup text always in the project base language regardless of the active language Prompt string is hard-coded in the script Move the prompt to a text list indexed by HmiRuntime.Language and read it from SmartTags at runtime
Project compiled but Runtime logs "ActiveX component can't create object: WScript.Shell" Windows Script Host disabled by group policy on the Runtime PC, or the runtime is locked down Enable WSH via Group Policy > Administrative Templates > Windows Components > Windows Script Host, or fall back to Approach A
Multiple confirmations overlap on the screen Operator double-taps the button before the OS dialog draws Disable the button while a confirmation is in flight with an internal "DialogOpen" tag, reset on dialog close

FAQ

Is the built-in MessageBox with OK and Cancel available in WinCC Flexible Runtime?

No, the WinCC Flexible function list does not expose a system MessageBox with OK and Cancel buttons on screen objects the way WinCC SCADA does. Implement the dialog with a pop-up image (Approach A) or with a VBScript call to WScript.Shell.Popup on a Windows-based runtime (Approach B/C).

What return value does WScript.Shell.Popup produce for OK and for Cancel?

OK returns 1, Cancel returns 2, and a timeout returns -1. Map the return value with a Select Case nPop block: Case 1 for OK and a default branch for Cancel / timeout / window-close.

Can the VBScript WSH approach be used on a SIMATIC CE panel?

No. CreateObject("WScript.Shell") is not available on Windows CE / WinCC flexible RT on CE panels. Use Approach A (pop-up image) on those targets, or implement a VBScript fallback that detects the missing COM object via On Error Resume Next / Err.Number and writes the tag with an authorization gate.

How is the VBScript helper called from a button in WinCC Flexible?

Open the button's Events > Click property, add a new function of type VBScript, and write the call such as ConfirmTag "Heater_Run", "Switch the heater ON?", "Operator confirmation". The helper itself must be declared in a project-wide VBScript module so the call resolves at compile time.

How do I make the confirmation prompt multilingual?

Store the prompt strings in a WinCC Flexible Text and Graphic List indexed by the active HMI language, and read the current entry in VBScript with SmartTags("ConfirmPrompt_" & HmiRuntime.Language). Pass the result as the Text argument to Popup. See the Microsoft MsgBox reference for the exact argument types.

Back to blog