Learning Foundation: Decision Logic
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.
Variables, comparisons and data conversion should already be clear.
Decision structures route process values into the correct operator message, command, alarm state or sequence branch.
Evaluate furnace temperature, fan status, process event and operating mode using If/ElseIf and Select Case.
Build readable branch logic with If, ElseIf, Else, And/Or/Not and Select Case without creating unsafe command logic.
Read/convert the working value
Evaluate engineering rule
Choose the matching path
Set message/status/request
Trace the selected branch
Complete WinCC VBScript Learning Path
Use Previous/Next for the recommended practical order, or open any topic below as a reference.
1. IF...THEN
Use a simple If when an action is required only when one condition is true.
If TempAct >= TempSet Then
EventTo = "TEMPERATURE ACHIEVED"
End If
2. IF...ELSE
Use Else when exactly two outcomes are required.
If FanStatus Then
EventTo = "FAN RUNNING"
Else
EventTo = "FAN STOPPED"
End If
3. IF...ELSEIF...ELSE
Use ElseIf for multiple ordered ranges.
If TempAct < TempSet - 20 Then
EventTo = "LOW TEMPERATURE"
ElseIf TempAct <= TempSet + 10 Then
EventTo = "TEMPERATURE NORMAL"
Else
EventTo = "HIGH TEMPERATURE"
End If
4. Nested IF
A nested If is useful when a secondary check only matters after a primary condition is satisfied.
If TempAct >= TempSet Then
If FanStatus Then
EventTo = "PROCESS READY"
Else
EventTo = "TEMP READY - FAN STOPPED"
End If
Else
EventTo = "TEMPERATURE NOT READY"
End If
5. AND — All Conditions Must Be True
Industrial permissives often require multiple conditions at the same time.
If TempAct >= TempSet _
And CpAct >= CpSet _
And OilAct >= OilSet _
And JacketAct >= JacketSet _
And FanStatus Then
EventTo = "PROCESS READY"
Else
EventTo = "PROCESS NOT READY"
End If
6. OR and NOT
Use Or when any listed condition may trigger the branch. Use Not to invert a Boolean condition.
If TempAct > TempSet + 20 Or OilAct < OilSet Then
EventTo = "PROCESS DEVIATION"
End If
If Not FanStatus Then
EventTo = "FAN NOT RUNNING"
End If
7. Select Case
Use Select Case when one variable has several discrete states.
Select Case SQFNo
Case 1
EventFrom = "SQF-01"
Case 2
EventFrom = "SQF-02"
Case 3
EventFrom = "SQF-03"
Case Else
EventFrom = "UNKNOWN SQF"
End Select
8. Select Case with Ranges
Case expressions can make range-based status logic easier to scan than a long chain of ElseIf statements.
Dim TempDeviation
TempDeviation = TempAct - TempSet
Select Case TempDeviation
Case Is < -20
EventTo = "LOW TEMPERATURE"
Case -20 To 10
EventTo = "TEMPERATURE NORMAL"
Case Else
EventTo = "HIGH TEMPERATURE"
End Select
9. Event_From → Event_To Mapping
A true transition requires both the previous state and the current state. Do not infer Event_From from FanStatus alone.
If PreviousFanStatus <> FanStatus Then
If PreviousFanStatus = False And FanStatus = True Then
EventFrom = "FAN STOP"
EventTo = "FAN START"
ElseIf PreviousFanStatus = True And FanStatus = False Then
EventFrom = "FAN START"
EventTo = "FAN STOP"
End If
End If
10. Decision Logic Syntax Cheat Sheet
Use this quick reference to choose the correct VBScript decision structure in WinCC.
| Keyword / Structure | Use | Core Syntax |
|---|---|---|
| If...Then | Run code only when one condition is true | If condition Then ... End If |
| If...Else | Choose between two outcomes | If condition Then ... Else ... End If |
| If...ElseIf...Else | Evaluate ordered multiple conditions | If c1 Then ... ElseIf c2 Then ... Else ... End If |
| Nested If | Run a secondary decision only after a primary condition | If c1 Then If c2 Then ... End If End If |
| And | Require every condition to be true | If c1 And c2 Then |
| Or | Allow any one condition to be true | If c1 Or c2 Then |
| Not | Invert a Boolean condition | If Not FanStatus Then |
| Select Case | Match one expression to several values | Select Case x ... Case 1 ... Case Else ... End Select |
| Case Is / To | Match ranges or comparison expressions | Case Is < -20 / Case -20 To 10 |
11. Participant Exercises
Complete these before loops and arrays.
SQF Running Project Lab · Blog 04
Build the SQF process-ready decision
If TempAct >= TempSet _
And CpAct >= CpSet _
And OilAct >= OilSet _
And JacketAct >= JacketSet _
And FanStatus Then
EventFrom = "PROCESS CHECK"
EventTo = "PROCESS READY"
Else
EventFrom = "PROCESS CHECK"
EventTo = "PROCESS NOT READY"
End If
Trainer Checkpoint
Participant should explain this chapter without copying the final program.
FAQs
Why does this tutorial use SQF_DB.dbo.tblEvent?
One stable industrial dataset lets participants learn VBScript progressively without changing examples in every chapter.
Should participants memorize the complete SQL logger now?
No. Learn the current chapter first. The complete WinCC-to-SQL program is assembled in later chapters.
Are HMIRuntime and ADODB VBScript keywords?
No. They are runtime/COM objects used by VBScript. The language keywords control how the script is structured.
