WinCC VBScript · Recipes · Batch Parameters

WinCC VBScript Recipe and Batch Parameter Management

Design validated, versioned and traceable recipe workflows for product changeover and batch setup using approved files, databases and PLC handshakes.

Guide Overview

Supporting WinCC VBS GuideStudy time: 80 minutesDifficulty: Intermediate-Advanced

What You Will Design

  • Versioned recipe records and validation rules
  • Staging, PLC apply and acknowledgment workflow
  • Audit, failure recovery and rollback checks

WinCC VBScript recipe and batch parameter management

This guide shows how to load, validate, stage and apply product parameters without treating a file read or HMI tag write as proof that the PLC accepted the recipe.

Process boundary: WinCC may select, validate and stage a recipe. The PLC must independently verify operating mode, equipment state, parameter limits, recipe identity and sequence readiness before applying values to control logic.

1. Choose native recipe functions before custom scripting

Use the supported WinCC recipe control or recipe system when it meets the operational requirement. A custom VBScript workflow is justified when an approved external CSV, legacy format, database interface or specialized audit process cannot be implemented cleanly with native configuration.

RequirementPreferred approach
Standard HMI recipe selection and transferNative WinCC recipe functions
Simple product parameter setVersioned native data record
Approved legacy CSV exchangeBounded VBS import/export with validation
Central multi-line recipe repositoryReviewed SQL or MES interface
Regulated electronic recordsValidated platform and approved audit-trail design

2. Define a versioned recipe data model

A recipe needs more than a list of values. Store identity and compatibility fields so the Runtime can reject the wrong product or schema.

  • Recipe ID and product code
  • Recipe name, revision and schema version
  • Approved status and effective date
  • Parameter name, value, unit and allowed range
  • Created, reviewed and modified metadata where required

Do not identify a recipe only by its filename. Validate the internal ID and schema after opening the record.

3. Validate each parameter before staging

Function IsRecipeValueValid(ByVal parameterName, ByVal proposedValue)
    IsRecipeValueValid = False
    If Not IsNumeric(proposedValue) Then Exit Function

    Dim value
    value = CDbl(proposedValue)

    Select Case CStr(parameterName)
        Case "FillTime_s"
            IsRecipeValueValid = (value >= 0.5 And value <= 30)
        Case "TargetVolume_ml"
            IsRecipeValueValid = (value >= 100 And value <= 2000)
        Case "ConveyorSpeed_pct"
            IsRecipeValueValid = (value >= 10 And value <= 100)
    End Select
End Function

Keep master limits in the PLC or approved configuration source. The HMI validation provides early feedback but is not the final control limit.

4. Parse a controlled CSV recipe file

Use a documented delimiter, invariant field order and explicit encoding. Reject missing columns, duplicate parameters and unknown names.

Function ParseRecipeLine(ByVal lineText)
    Dim fields
    fields = Split(CStr(lineText), ",")

    If UBound(fields) <> 2 Then
        ParseRecipeLine = ""
        Exit Function
    End If

    If Not IsRecipeValueValid(Trim(fields(0)), Trim(fields(1))) Then
        ParseRecipeLine = ""
        Exit Function
    End If

    ParseRecipeLine = Trim(fields(0)) & "|" & _
        Trim(fields(1)) & "|" & Trim(fields(2))
End Function

For text values containing delimiters or quotes, use a proper reviewed CSV parser or a simpler approved exchange format rather than expanding ad hoc splitting logic.

5. Stage recipe values before PLC application

Write validated values to dedicated staging tags. Do not overwrite active control parameters one by one while parsing the file.

Sub StageBottleRecipe(ByVal fillTime, ByVal targetVolume, ByVal speedPercent)
    HMIRuntime.Tags("Recipe_Stage_FillTime_s").Write CDbl(fillTime)
    HMIRuntime.Tags("Recipe_Stage_TargetVolume_ml").Write CDbl(targetVolume)
    HMIRuntime.Tags("Recipe_Stage_ConveyorSpeed_pct").Write CDbl(speedPercent)
    HMIRuntime.Tags("Recipe_Stage_Valid").Write 1
    HMIRuntime.Trace "Recipe values staged for PLC validation" & vbCrLf
End Sub

Clear the valid flag whenever parsing, validation or communication fails.

6. Use an apply-request and acknowledgment handshake

  1. WinCC stages every validated value and the recipe ID.
  2. WinCC increments a request ID or sets an apply-request bit.
  3. The PLC confirms machine state and validates the entire parameter set.
  4. The PLC copies accepted values atomically into active parameters.
  5. The PLC returns accepted, rejected or timeout status with a reason code.
  6. WinCC displays the applied recipe ID and PLC acknowledgment.

This prevents a partial recipe from becoming active when communication fails during transfer.

7. Save approved parameters to CSV or SQL Server

When exporting a recipe, write to a temporary file or transaction first, verify completion and then publish the new revision. For shared recipe repositories, use SQL constraints, transactions and role-based access.

  • Do not overwrite the only approved recipe copy.
  • Store a new revision with a clear effective state.
  • Parameterize SQL values and allowlist identifiers.
  • Record affected-row count and transaction result.

Continue with Export WinCC tag data to CSV and WinCC VBScript SQL Server CRUD operations.

8. Record recipe and batch audit context

A useful record identifies the recipe, revision, batch, equipment, request time, PLC result and responsible user where collection is approved.

Audit fieldPurpose
Recipe ID and revisionIdentify the parameter set requested
Batch or order IDConnect parameters to production context
Request and acknowledgment timeMeasure transfer and acceptance sequence
PLC result codeDistinguish applied, rejected and timed-out requests
Changed parametersSupport review and troubleshooting

Regulated audit trails require validated controls beyond an ordinary text log. Follow the applicable quality and records-management requirements.

9. Recover from missing, invalid or partial recipes

  • Keep the currently active PLC recipe unchanged after a failed import.
  • Clear HMI staging-valid state and show the exact validation failure.
  • Do not retry an apply request indefinitely.
  • Preserve the last known approved recipe and its revision.
  • Require a controlled rollback rather than editing active values manually.

10. Batch execution and recipe changes

Do not permit an uncontrolled recipe change during an active batch. The PLC or batch system should expose states such as Idle, Ready, Running, Held and Complete, with a defined rule for when a new recipe may be staged or applied.

11. Commissioning test matrix

TestExpected result
Unknown recipe IDRejected before staging
Wrong schema versionRejected with compatibility message
Value outside rangeNo apply request; failed parameter identified
Communication loss during transferActive PLC recipe remains unchanged
Recipe request during active batchPLC rejects or defers according to specification
Duplicate request IDNo duplicate application
Authorized rollbackPrevious approved revision restored and recorded

12. Bottling-line recipe example

A bottle recipe contains target volume, fill time and conveyor speed. WinCC loads and validates a selected revision, stages all values, and submits one apply request. The PLC accepts the recipe only while the filler is Idle and all limits are valid. The resulting batch record stores the recipe revision and PLC acknowledgment rather than assuming that file import alone completed the changeover.

Frequently asked questions

Should a custom VBScript replace WinCC Recipe Management?

No. Use native recipe functions when they meet the requirement. Custom VBS is appropriate only for a justified and reviewed external workflow.

Can WinCC write active PLC parameters directly?

The safer design stages values and lets the PLC validate and apply the complete set atomically.

Is CSV suitable for every recipe system?

No. CSV can suit small controlled exchanges but lacks the concurrency, access control and transaction support of a database or validated recipe platform.

How should recipe rollback work?

Restore a known approved revision through the same validation and PLC acknowledgment process, and record the rollback result.

Get the WinCC VB Scripting syllabus

Request practical online, classroom or corporate training details.

Build reliable WinCC VBScript projects

Join practical online, classroom or corporate training.

Request Course Details
Verified learning pathway

Discuss WinCC VB Scripting Training

Explore practical WinCC VBS, SCADA, SQL reporting and industrial automation training options.

Content reviewed: 4 August 2026

☎ Call WhatsApp ✉ Email Enquire Now