<!-- Softwell WinCC VBScript 20-Part Tutorial · Blog 13 · updated 2026-08-29 --> WinCC VBScript Recipe and Batch Parameter Management | Softwell
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

Learning Foundation: Controlled Parameter Transfer

This page has one defined job in the WinCC VBScript learning path. Master this foundation before using the same concept inside larger SCADA, SQL Server and reporting scripts.

Intermediate to AdvancedWinCC Explorer / Classic WinCCSQF Running Project
Prerequisite

Validated operator input, tag writes, reusable functions and diagnostics.

Core concept

Recipe workflows require validation, staging, controlled apply requests, PLC acknowledgement and traceable context.

SQF practical connection

Stage temperature, CP, oil and jacket setpoints for a charge, then apply them as one validated recipe transaction/request.

Expected competency

Build recipe/batch parameter workflows without directly scattering uncontrolled tag writes across the HMI.

WinCC VBScript Recipe and Batch Parameter Management — ArchitectureCode-rendered HTML/CSS architecture; no image file required
Recipe Select

Choose product/charge recipe

RecipeID
Validate

Check every parameter

Temp / CP / Oil
Stage Tags

Load temporary values

Recipe_*
PLC Apply

Write apply request

Recipe_Apply
Acknowledge / Audit

Confirm and record result

Ack / SQL

Complete WinCC VBScript Learning Path

Use Previous/Next for the recommended practical order, or open any topic below as a reference.

WinCC VB Scripting Training →
Easy Testing Method: Every main code example on this page is followed by a copy-ready InputBox + MsgBox test. Use the dialog version first to understand the result, then move to the original WinCC/SQL code. Database writes and equipment commands are previewed or simulated unless the original example is already intended as a lab action.

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

Easy TestEasy Test 1 — InputBox + MsgBox

A self-contained function test using the same setpoint/actual-value pattern as the SQF project.

Function TestIsOK(ByVal SetValue, ByVal ActualValue)
    TestIsOK = (ActualValue >= SetValue)
End Function

Dim SP, PV
SP = CDbl(InputBox("Enter Setpoint", "Easy Test 1 — InputBox + MsgBox", "850"))
PV = CDbl(InputBox("Enter Actual Value", "Easy Test 1 — InputBox + MsgBox", "825"))

MsgBox "Setpoint = " & SP & vbCrLf & _
       "Actual = " & PV & vbCrLf & _
       "Function Result = " & TestIsOK(SP, PV), _
       vbInformation, "Function Quick Test"

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

Easy TestEasy Test 2 — InputBox + MsgBox

A self-contained function test using the same setpoint/actual-value pattern as the SQF project.

Function TestIsOK(ByVal SetValue, ByVal ActualValue)
    TestIsOK = (ActualValue >= SetValue)
End Function

Dim SP, PV
SP = CDbl(InputBox("Enter Setpoint", "Easy Test 2 — InputBox + MsgBox", "850"))
PV = CDbl(InputBox("Enter Actual Value", "Easy Test 2 — InputBox + MsgBox", "825"))

MsgBox "Setpoint = " & SP & vbCrLf & _
       "Actual = " & PV & vbCrLf & _
       "Function Result = " & TestIsOK(SP, PV), _
       vbInformation, "Function Quick Test"

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

Easy TestEasy Test 3 — InputBox + MsgBox

Write is simulated to avoid accidental equipment commands during beginner testing.

Dim TestValue
TestValue = InputBox("Enter value to test for WinCC tag: Recipe_Stage_FillTime_s", "Easy Test 3 — InputBox + MsgBox", "1")
If TestValue = "" Then
    MsgBox "Test cancelled.", vbInformation, "Tag Write Quick Test"
Else
    MsgBox "SIMULATION ONLY" & vbCrLf & _
           "Tag: Recipe_Stage_FillTime_s" & vbCrLf & _
           "Value that would be written: " & TestValue & vbCrLf & vbCrLf & _
           "After checking interlocks, use the original .Write code above in Runtime.", _
           vbInformation, "Tag Write Quick Test"
End If

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.

SQF Running Project Lab · Blog 13

Treat furnace setpoints as one recipe group

Dim TempSet, CpSet, OilSet, JacketSet
TempSet = HMIRuntime.Tags("Temp_Set").Read
CpSet = HMIRuntime.Tags("Cp_Set").Read
OilSet = HMIRuntime.Tags("Oil_Set").Read
JacketSet = HMIRuntime.Tags("Jacket_Set").Read

Easy TestEasy Test 4 — InputBox + MsgBox

Offline tag simulation: useful before connecting the participant PC to WinCC Runtime.

Dim TestValue, ResultText
ResultText = ""
TestValue = InputBox("Enter simulated value for Temp_Set", "Easy Test 4 — InputBox + MsgBox", "825.5")
ResultText = ResultText & "Temp_Set = " & TestValue & vbCrLf
TestValue = InputBox("Enter simulated value for Cp_Set", "Easy Test 4 — InputBox + MsgBox", "825.5")
ResultText = ResultText & "Cp_Set = " & TestValue & vbCrLf
TestValue = InputBox("Enter simulated value for Oil_Set", "Easy Test 4 — InputBox + MsgBox", "825.5")
ResultText = ResultText & "Oil_Set = " & TestValue & vbCrLf
TestValue = InputBox("Enter simulated value for Jacket_Set", "Easy Test 4 — InputBox + MsgBox", "825.5")
ResultText = ResultText & "Jacket_Set = " & TestValue & vbCrLf
MsgBox ResultText & vbCrLf & "Now compare these values with the original HMIRuntime .Read example.", vbInformation, "Tag Read Quick Test"
A recipe/batch workflow should validate the whole approved parameter set before transfer or storage.

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