Scripts Expressions(Reference) provide lightweight, event-driven automation for simple calculations and method calls, ideal for scenarios with many triggers but straightforward logic. A Script Expression is single-line statements that:
Use Expressions when you need many simple automations that would otherwise require numerous one-line tasks. The parse of the expression is VB.NET syntax, but it automatically converts and accepts C# syntax also.
Property | Description |
---|---|
Object | Tag or object that receives the expression result |
Expression | VB.NET statement (arithmetic, conditional, or method call) |
Domain | Server (global) or Client (local) execution |
Execution | When expression runs (see Execution Modes) |
Trigger | Tag/object that triggers execution (optional) |
DisableCondition | Tag/object that disables execution when true |
Time | Specific time for time-based execution |
Label | User-defined label for organization |
BuildStatus | ? Green = Success, ? Red = Errors |
BuildErrors | Compilation error details |
BuildMessages | Status messages after verification |
Mode | Description | Use Case |
---|---|---|
OnChange | Runs when any tag in expression changes | Real-time calculations |
TriggerOrTimeInterval | Runs on trigger change OR time interval | Periodic updates with override |
ChangeOrStartup | Runs on tag change OR at startup | Initialize and maintain values |
TriggerOrTimeOfDay | Runs on trigger OR specific time | Scheduled operations with manual trigger |
<ac:structured-macro ac:name="info"> ac:rich-text-body Automatic Conversions: The platform automatically converts C#-style operators to VB.NET:
==
becomes =
@
prefix needed for tags (unlike Script Tasks) </ac:rich-text-body> </ac:structured-macro>vbnet
' No @ symbol needed in expressions
Tag.Temperature * 1.8 + 32 ' Convert C to F
Tag.Output = Tag.Input1 + Tag.Input2
vbnet
' Call methods from Script Classes
Script.Class.Calculations.GetAverage(Tag.Value1, Tag.Value2)
Script.Class.DataProcessor.Validate(Tag.RawData)
vbnet
' Standard .NET operators
(Tag.Flow * Tag.Density) / 1000
Math.Round(Tag.Value, 2)
Math.Max(Tag.Limit, Tag.Current)
Evaluates all parameters regardless of condition:
vbnet
IIF(Tag.Status = 1, "Running", "Stopped")
' Both "Running" and "Stopped" are evaluated
IIF(Tag.Level > 80, Script.Class.Alerts.High(), Script.Class.Alerts.Normal())
' WARNING: Both High() and Normal() methods execute!
Evaluates only the selected branch:
vbnet
TIF(Tag.Status = 1, "Running", "Stopped")
' Only evaluates the matching result
TIF(Tag.Level > 80, Script.Class.Alerts.High(), Script.Class.Alerts.Normal())
' Only executes High() OR Normal(), not both
<ac:structured-macro ac:name="warning"> ac:rich-text-body Important: Use TIF instead of IIF when calling methods to avoid unnecessary execution. </ac:rich-text-body> </ac:structured-macro>
<ac:structured-macro ac:name="info"> ac:rich-text-body Default Setting: Client-side expressions are disabled by default for web compatibility. Enable in Solution → Settings if needed. </ac:rich-text-body> </ac:structured-macro>
vbnet
' Temperature conversion
Tag.TempF = Tag.TempC * 1.8 + 32
' Percentage calculation
Tag.Efficiency = (Tag.Actual / Tag.Target) * 100
' Conditional assignment
Tag.Status = TIF(Tag.Value > 100, 2, 1)
vbnet
' Reset counter at midnight
Tag.DailyCount = 0 ' Execution: TriggerOrTimeOfDay, Time: 00:00
' Calculate hourly average
Tag.HourlyAvg = Script.Class.Statistics.GetHourlyAverage()
vbnet
' Call complex processing in Script Class
Script.Class.Production.CalculateOEE()
' Conditional processing
TIF(Tag.AlarmActive, Script.Class.Alerts.Send(), 0)
Expression not executing:
Performance issues:
Compilation errors:
Unexpected results: