Siemens TIA Portal I/O Field: Dynamic Decimal Place Formatting

David Krause13 min read
HMI ProgrammingSiemensTutorial / 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

Overview

Siemens TIA Portal HMI I/O fields display process values in a fixed format defined at engineering time. The Display format or Representation property sets the decimal count statically (for example, 999, 999.9, 999.99, 999.999). When an operator must be able to change the resolution of an analog readout at runtime — selecting 0, 1, 2, or 3 decimal places from a separate I/O field — a static format string is no longer sufficient.

This article covers three production-ready techniques for the TP 1200 Comfort (WinCC Comfort / Advanced) and the WinCC Unified runtime, plus a structured assessment of the legacy "four I/O fields with visibility animation" workaround that is currently deployed at the customer site. Each technique is documented with the exact configuration path, the VBScript snippet to use where applicable, and the verification steps required at HMI commissioning.

Engineering constraint: The runtime's "Number of decimal places" property of an I/O field is a compile-time attribute on the screen object. It cannot be written to from a script on WinCC Comfort / Advanced. The value can only be changed at design time or by swapping the visible screen object. This is the root cause of the workaround pattern seen in the field.

Prerequisites

Item Requirement
Engineering software SIMATIC TIA Portal V17 or later (V20 recommended for Unified improvements)
HMI runtime – Comfort path WinCC Comfort V17 / V18 / V19 / V20 (TP 1200 Comfort, TP 1500 Comfort, TP 2200 Comfort, KP 1500 Comfort)
HMI runtime – Unified path WinCC Unified V18 or later (Unified Comfort Panels, Unified PC Runtime)
PLC side SIMATIC S7-300 / S7-400 / S7-1500, either inside the same TIA Portal project or in a legacy STEP 7 V5.x / SIMATIC Manager project
License WinCC Comfort / Unified configuration license; VBScript runtime is included with WinCC Comfort / Advanced — no separate scripting license is required
Tag rights The script must write to an HMI tag that the operator I/O field references. PLC tags in %DB / %IW areas are read-only from a screen script

Technique A — VBScript with FormatNumber on WinCC Comfort / Advanced

This is the canonical solution for a TP 1200 Comfort panel. The decimal selection is implemented in a single HMI tag of type Integer. A VBScript is fired on the ValueChange event of the selector I/O field. The script reads the source analog value, applies FormatNumber, and writes the result to a display HMI tag of type String. The visible I/O field is bound to the string tag, not the raw process tag, so the format can change every time the operator modifies the selector.

Step 1 — Declare the three HMI tags

  1. In the TIA Portal project tree, open HMI tags on the Comfort panel.
  2. Create tag ProcessValue, type Real, connection to the PLC tag that carries the analog value (for example, DB101.DBD0).
  3. Create tag NumberOfDecimals, type Int (or USInt), range 0 – 3. This is the user-selectable parameter.
  4. Create tag ProcessValueText, type WString (recommended for Unicode-safe logging) or String. The visible I/O field is bound to this tag.

Step 2 — Create the VBScript

Under Scripts > VBScripts on the HMI, add a new function. WinCC Comfort / Advanced exposes the legacy SmartTags() collection, but in TIA Portal V17 and later the recommended access pattern is the HMIRuntime.Tags API. The snippet below is fully TIA Portal V17–V20 compatible.

' VBScript: FormatProcessValue
' Trigger: ValueChange event of HMI tag "NumberOfDecimals"

Dim dec
Dim raw
Dim txt
Dim srcTag, dstTag

Set srcTag = HMIRuntime.Tags("ProcessValue")
Set dstTag = HMIRuntime.Tags("ProcessValueText")

srcTag.Read
dec = CInt(HMIRuntime.Tags("NumberOfDecimals").Read)

' Clamp the value to the allowed 0..3 range to avoid FormatNumber errors
If dec < 0 Then dec = 0
If dec > 3 Then dec = 3

raw = CDbl(srcTag.Value)
txt = FormatNumber(raw, dec, vbTrue, vbFalse, vbFalse)

dstTag.Write txt
FormatNumber signature: FormatNumber(Expression [, NumDigitsAfterDecimal [, IncludeLeadingDigit [, UseParensForNegativeNumbers [, GroupDigits]]]]). The default on a German / European Windows image uses the system locale's decimal separator (comma). For consistent screen output regardless of regional settings, replace the final assignment with Replace(txt, ".", ",") on a comma-decimal HMI, or with Replace(txt, ",", ".") if you need canonical point decimals for downstream logging.

Step 3 — Wire the script to the event

  1. Select the decimal-selector I/O field on the screen.
  2. Open Properties > Events > ValueChange.
  3. Add a new function list, drop in the FormatProcessValue VBScript, and close the dialog.

Step 4 — Bind the display I/O field

  1. Drop the analog display I/O field on the screen and set Mode to Output.
  2. Set Process value to the tag ProcessValueText (String / WString).
  3. Set Display format to String so the I/O field does not try to re-parse the formatted text as a number.

Step 5 — Bind the selector I/O field

  1. Set the selector I/O field's Process value to NumberOfDecimals (Int).
  2. Set Mode to Input/Output so the operator can edit the value at runtime.
  3. Optional: configure the Lower limit = 0 and Upper limit = 3 to prevent out-of-range entries.

Technique B — WinCC Unified "Shift decimal places" property

WinCC Unified runtime (Unified Comfort Panels, Unified PC Runtime) added a Shift decimal places property to the I/O field object starting with TIA Portal V18, and the property was refined in the V20 Update 3 release notes. According to the official Siemens documentation at SIEMENS Support entry 109816808, the property automatically multiplies or divides the integer tag by a power of 10 at the screen-object level, so a tag holding the raw integer 12345 can be displayed as 1.2345 simply by setting the shift value to 4. The feature is described in the TIA Portal V20 release notes at I/O field: 'Shift decimal places' property.

Step 1 — Configure the I/O field

  1. Select the I/O field on the Unified screen.
  2. Open the Properties &strong> inspector > General.
  3. Set the bound tag to an integer value (the raw process value scaled by 10n).
  4. Set the new Shift decimal places property to the desired shift count (for example, 2 to display 12345 as 123.45).

Step 2 — Drive the shift at runtime

Because the shift is still a compile-time property, dynamic runtime change still requires a script. The Unified VBScript syntax differs from WinCC Comfort / Advanced: tags are accessed through the HMIRuntime object and screen-object properties are set via the Screen.Items(...) collection.

' Unified VBScript: SetShift
' Trigger: ValueChange of the decimals selector tag

Dim n
n = CInt(HMIRuntime.Tags("NumberOfDecimals").Read)
If n < 0 Then n = 0
If n > 3 Then n = 3

' Apply shift to the named I/O field on the active screen
Screen.Items("IOField_ProcessValue").ShiftDecimalPlaces = n
Runtime check: The ShiftDecimalPlaces property of the Unified I/O field accepts integer values in the range supported by the underlying display format. Values outside the configured Display format range (for example, shift of 4 when the format only shows three decimal places) will clip the result. Always size the display format large enough to contain the maximum shift value the operator can request.

Technique C — Multiple I/O fields with visibility animation (legacy workaround)

This is the technique the customer is currently using. It is fully supported on Basic Panels as well, where VBScript and the Unified shift property are not available. The implementation cost scales linearly with the number of source values and is the main reason engineers search for alternatives: 30 analog values × 4 decimal formats = 120 I/O fields.

Step 1 — Pre-build the four format variants

  1. For each analog source tag, create four I/O fields on the screen.
  2. Set their Display format strings to 999, 999.9, 999.99, and 999.999 respectively.
  3. Stack the four I/O fields at the same screen coordinates so they visually overlap.

Step 2 — Animate visibility

  1. Open the Animations > Visibility dialog of the first I/O field.
  2. Add a new animation that evaluates the value of the HMI tag NumberOfDecimals.
  3. Use the table-driven form (PLC tag = value) or an expression such as NumberOfDecimals == 0 to map the tag value to the corresponding I/O field's visibility.

Step 3 — Repeat for the other three formats

Map the same NumberOfDecimals tag to the visibility of the remaining three I/O fields with the conditions == 1, == 2, and == 3. At any moment exactly one of the four fields is visible.

Memory and update cost: The visibility animation re-evaluates on every tag change of the bound source. With 30 values × 4 fields, the runtime updates 120 screen objects on every PLC cycle. This is well within the capabilities of a TP 1200 Comfort, but it inflates the project's load on the HMI's internal storage and lengthens screen open / re-paint time. The VBScript solution removes the 3:1 field multiplier.

Cross-project configuration — TIA Portal HMI + SIMATIC Manager PLC

A frequently-asked follow-up in the field is whether the VBScript approach works when only the HMI has been migrated to TIA Portal while the PLC is still programmed in STEP 7 V5.x (SIMATIC Manager). The answer is yes, with two important constraints.

Constraint 1 — Tag access direction

The HMI accesses the SIMATIC Manager PLC through an HMI connection configured with the PLC's MPI / PROFIBUS / Ethernet address. Tags are read-only mirrors of PLC addresses; the script cannot write back to a DB in the S7-300 / S7-400 project from a Comfort panel. The script must read the analog value and write the formatted text to a local HMI tag on the panel.

Constraint 2 — Tag type and HMI-side storage

Local HMI tags are stored in the panel's internal tag memory and survive power cycles only if the tag is marked as Persistent. The ProcessValueText tag from Technique A is a String / WString of length 16, which is well within the Comfort panel's tag memory budget. The persistence flag is not required for the formatted text since it is recomputed on every ValueChange of the selector.

Code that works across the two projects

' TIA Portal HMI, VBScript — usable when the PLC lives in SIMATIC Manager
' The PLC connection is an HMI connection of type "SIMATIC S7 300/400"

Dim src, dec, txt

' src.Value is automatically updated by the HMI's polling cycle
src = SmartTags("ProcessValue")
dec = SmartTags("NumberOfDecimals")

If dec < 0 Then dec = 0
If dec > 3 Then dec = 3

txt = FormatNumber(src, dec, vbTrue, vbFalse, vbFalse)
SmartTags("ProcessValueText") = txt

Both SmartTags("ProcessValue") (the S7-300 / S7-400 DB mirror) and SmartTags("ProcessValueText") (the local HMI tag) are visible in the VBScript because the script runs inside the TIA Portal HMI project; the script does not care which project the source PLC tag was originally configured in.

Solution comparison

Criterion VBScript + FormatNumber (Comfort) Unified Shift decimal places Multiple I/O fields + visibility
Panels supported Comfort, WinCC Advanced PC Runtime Unified Comfort, Unified PC Runtime Basic, Comfort, Unified
Configuration effort per value 1 I/O field + 1 script reference 1 I/O field + 1 script reference 4 I/O fields + 4 visibility animations
Total objects for 30 values 30 I/O fields + 1 script 30 I/O fields + 1 script 120 I/O fields
Scripting required Yes (VBScript) Yes (VBScript, Unified API) No
Dynamic shift at runtime Yes, via string tag Yes, via screen-object property Indirect, via visibility swap
Basic Panel support No (no VBScript) No (Unified only) Yes
Cycle-time impact Script runs only on ValueChange — negligible Property write runs only on ValueChange — negligible 120 visibility re-evaluations per cycle
Cross-project (TIA + SIMATIC Manager) Supported Supported Supported

Verification and commissioning

  1. Compile and download the HMI project to the TP 1200 Comfort. Start the runtime.
  2. Force the PLC tag ProcessValue to four representative values: 0, 1.2345, -1.2345, and 99999.9999 (clamp to the configured display range).
  3. Cycle the selector I/O field through 0, 1, 2, 3 and confirm the visible readout matches the requested precision.
  4. Enter a value of 5 into the selector and confirm the clamping logic falls back to 3 decimal places.
  5. Open the HMI's diagnostic view (Control Panel > System > Runtime Logs) and verify that the FormatNumber script has not raised an exception.
  6. Power-cycle the panel. The selector value should be retained if the tag is marked as Persistent; the formatted text will be recomputed on the first ValueChange.

Troubleshooting matrix

Symptom Likely cause Corrective action
Displayed value never updates Script not bound to ValueChange of NumberOfDecimals Re-check the event list; ensure the function is the top entry and that the function list is enabled
Display shows raw integer instead of formatted string Display I/O field is bound to the Real process tag, not to ProcessValueText Change the Process value property of the display field to the String / WString tag
Format shows wrong decimal separator (comma vs. point) Region settings of the HMI's Windows image Apply explicit Replace() on the formatted string to normalize the separator
Script aborts with type-mismatch on the first run Source tag has not been read yet, src.Value is Empty Force an explicit srcTag.Read before CDbl(srcTag.Value) or guard with If IsNumeric(...)
Unified: ShiftDecimalPlaces property write throws Object name does not exist on the current screen Verify spelling of the screen item in Screen.Items(...); check the screen's Items collection in the engineering view
Visibility workaround: more than one field visible Animation conditions overlap (for example >= 1 on two fields) Use strict equality (== 0, == 1, …) for the four visibility animations

Field-proven caveats

  • Logarithmic displays: FormatNumber does not respect the Display format property of the I/O field. If the HMI screen uses a five-digit 99999 format and the process value exceeds it, FormatNumber will still return the full text. Pad the display I/O field with a 16-character String tag to be safe.
  • Engineering language: The script editor of WinCC Comfort / Advanced is English-only; comments inside the script must use English identifiers even on a Chinese or German localization. vbTrue and vbFalse are the locale-independent constants.
  • Alarm acknowledgment: Alarms that reference the raw process tag remain triggered by the original value, not by the formatted string. The string tag is purely a display artifact.
  • Audit trail: On regulated sites, the formatted string is not acceptable as a logged value. Always log the raw Real tag, never the formatted String tag.

How do I change the number of decimal places dynamically on a TP 1200 Comfort I/O field?

Add an integer HMI tag (for example NumberOfDecimals, 0 – 3), bind it to a selector I/O field with a ValueChange event, and run a VBScript that reads the analog tag, calls FormatNumber(raw, dec), and writes the result to a String HMI tag. Bind the visible I/O field to that string tag in String display mode.

Why are four I/O fields stacked with visibility animation a poor solution for 30 values?

It requires 120 I/O fields plus 120 visibility animations, inflates the screen build / repaint time, and makes future changes (adding a new decimal option) expensive. A single VBScript driving a String tag replaces all of that with 30 I/O fields and one script reference.

Does the "Shift decimal places" property work on TP 1200 Comfort panels?

No. The property is part of WinCC Unified. TP 1200 Comfort runs WinCC Comfort / Advanced and must use the VBScript + FormatNumber approach. The property is documented in SIEMENS Support entry 109816808 and in the TIA Portal V20 Update 3 release notes.

Can the VBScript run when the PLC is in SIMATIC Manager and the HMI is in TIA Portal?

Yes. The script runs in the TIA Portal HMI project and reads the SIMATIC Manager PLC through an HMI connection. The formatted result is written to a local HMI tag (String / WString) on the Comfort panel. The script does not write back to the PLC.

What happens if the operator enters a value outside 0 – 3 into the decimal selector?

With the clamping code in the script (If dec < 0 Then dec = 0, If dec > 3 Then dec = 3), the field falls back to the nearest valid value. Without the clamp, FormatNumber may return a string with more decimal places than the display I/O field can render, producing truncated output.

Back to blog