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:

  • Execute on events or schedules without creating full tasks
  • Run in multi-threaded environment for optimal performance
  • Automatically detect tag changes in the expression
  • Support both arithmetic operations and Script Class calls

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.

In this page:

Creating Script Expressions

  1. Navigate to Scripts → Expressions
  2. Select insert row (first blank row)
  3. Configure:
    • Object: Target tag to receive result
    • Expression: VB.NET statement or calculation
    • Execution: Trigger method
    • Domain: Server (default) or Client

Configuration Properties

PropertyDescription
ObjectTag or object that receives the expression result
ExpressionVB.NET statement (arithmetic, conditional, or method call)
DomainServer (global) or Client (local) execution
ExecutionWhen expression runs (see Execution Modes)
TriggerTag/object that triggers execution (optional)
DisableConditionTag/object that disables execution when true
TimeSpecific time for time-based execution
LabelUser-defined label for organization
BuildStatus? Green = Success, ? Red = Errors
BuildErrorsCompilation error details
BuildMessagesStatus messages after verification

Execution Modes

ModeDescriptionUse Case
OnChangeRuns when any tag in expression changesReal-time calculations
TriggerOrTimeIntervalRuns on trigger change OR time intervalPeriodic updates with override
ChangeOrStartupRuns on tag change OR at startupInitialize and maintain values
TriggerOrTimeOfDayRuns on trigger OR specific timeScheduled operations with manual trigger

Expression Syntax

Key Syntax Rules

<ac:structured-macro ac:name="info"> ac:rich-text-body Automatic Conversions: The platform automatically converts C#-style operators to VB.NET:

  • == becomes =
  • No semicolon needed at the end
  • No @ prefix needed for tags (unlike Script Tasks) </ac:rich-text-body> </ac:structured-macro>

Direct Tag Access

vbnet

' No @ symbol needed in expressions
Tag.Temperature * 1.8 + 32  ' Convert C to F
Tag.Output = Tag.Input1 + Tag.Input2

Calling Script Classes

vbnet

' Call methods from Script Classes
Script.Class.Calculations.GetAverage(Tag.Value1, Tag.Value2)
Script.Class.DataProcessor.Validate(Tag.RawData)

Arithmetic Operations

vbnet

' Standard .NET operators
(Tag.Flow * Tag.Density) / 1000
Math.Round(Tag.Value, 2)
Math.Max(Tag.Limit, Tag.Current)

Conditional Evaluation Methods

IIF Method (Immediate If)

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>


Threading and Performance

Multi-Threading

  • Each expression executes in thread pool
  • Hundreds/thousands of expressions don't block each other
  • Automatic thread management
  • No manual synchronization needed

Compilation

  • Automatic compilation before runtime
  • Manual verification available via button
  • All expressions compile together
  • No need to compile after each change

Domain Execution

<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>

Server Domain (Default)

  • Executes on server (TServer.exe)
  • Global scope
  • Typical use: Calculations, business logic

Client Domain

  • Executes on each client
  • Local scope
  • Only for WPF clients (not web)
  • Typical use: UI calculations, local formatting

Examples

Simple Calculations

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)

Time-Based Operations

vbnet

' Reset counter at midnight
Tag.DailyCount = 0  ' Execution: TriggerOrTimeOfDay, Time: 00:00

' Calculate hourly average
Tag.HourlyAvg = Script.Class.Statistics.GetHourlyAverage()

Complex Logic via Classes

vbnet

' Call complex processing in Script Class
Script.Class.Production.CalculateOEE()

' Conditional processing
TIF(Tag.AlarmActive, Script.Class.Alerts.Send(), 0)

Best Practices

  • Use for simple logic - Complex code belongs in Script Tasks or Classes
  • Prefer TIF over IIF - Avoid unnecessary method execution
  • Group related expressions - Use Label field for organization
  • Monitor performance - Many OnChange expressions can impact performance
  • Test with Verify - Use button to check syntax before runtime
  • Consider execution mode - Choose appropriate trigger method
  • Document purpose - Use Label field to explain expression

Troubleshooting

Expression not executing:

  • Check BuildStatus for compilation errors
  • Verify DisableCondition is not active
  • Confirm Domain matches deployment
  • Check trigger tag is changing

Performance issues:

  • Review OnChange expressions for high-frequency tags
  • Consider time-based instead of change-based
  • Move complex logic to Script Classes
  • Check for IIF with method calls

Compilation errors:

  • Click Verify button to see errors
  • Check VB.NET syntax (not C#)
  • Verify referenced tags exist
  • Ensure Script Classes are compiled

Unexpected results:

  • Remember IIF evaluates all branches
  • Check automatic operator conversion
  • Verify tag data types match
  • Test with simpler expression first




In this section...



  • No labels