Data manipulation logic examples
- Last UpdatedNov 16, 2022
- 1 minute read
Simple expressions with arithmetic operators
[FIELD]
FIELD(1).Type = "String"
FIELD(2).Type = "Number"
Data file content: ' 001, Value: 1.23
Create a tag name using the '&' operator and scale the value by a factor of 100.
FIELD(1) = C1 – (",")
FIELD(1) = "TAG_" & FIELD(1)
Extract the value and scale it.
FIELD(2) = C12 – NEWLINE
FIELD(2) = 100 * FIELD(2)
Mathematical functions
[FIELD]
FIELD(1).Type = "Number"
FIELD(2).Type = "Number"
Data file content: ' Value1: 1.23; Value2: 2.61
FIELD(1) = ["*(*);*:*"]
FIELD(2) = ["*:*;*(*)"]
Apply ROUND().
FIELD(1) = ROUND(FIELD(1))
FIELD(2) = ROUND(FIELD(2))
String functions
[FIELD]
FIELD(1).Type = "String"
Replace string data with an error.
FIELD(1) = C10 – NEWLINE
FIELD(1) = REPLACE(FIELD(1), "Invalid string part", "OK")
Sub-milliseconds
Data file content: 01-Jul-2006 08:00:00.1234; 123
[FIELD]
FIELD(1).Type = "DateTime"
FIELD(1).Format = "dd-MMM-yyyy hh:mm:ss.nnn"
FIELD(2).Type = "Number"
[MSG(1)]
PI supports time precision up to 15 microseconds.
FIELD(1) = C1 – (";")
Extract the number after the semicolon:
FIELD(2) = ["*;(*)"]
Date math
Use "-" or "+" to conditionally adjust for daylight saving time.
[FIELD]
FIELD(1).NAME = "TimeStamp"
FIELD(1).TYPE = "DateTime"
FIELD(1).FORMAT = "dd-MMM-yyyy hh:mm:ss"
FIELD(2).NAME = "TimeOffset"
FIELD(2).TYPE = "Time"
FIELD(2).FORMAT = "hh:mm:ss"
TimeOffset = "01:00:00"
If( TimeStamp >= "25-Mar-2014 03:00:00" AND TimeStamp < "28-Oct-2014 03:00:00") Then
TimeStamp = TimeStamp - TimeOffset EndIf