Expressions
Overview
Expressions can include a combination of variables, constants, operators, functions, and references to label Items as well as to data fields in a data binding scenario. The Expression is set to any Item in the label through the Expression property and is used to dynamically set the Item's content. The following are the Items that currently support expressions:
- TextItem: any expression will be evaluated to set the Text property.
- BarcodeItem: any expression will be evaluated to set the Code property.
- ImageItem: any expression will be evaluated to set the SourceFile or SourceBase64 property.
- RFIDTagItem: any expression will be evaluated to set the DataToEncode property.
- LiteralItem: any expression will be evaluated to set the Text property.
Note
Expressions are evaluated by ThermalLabel SDK at label rendering stage and it's the last step that will finally set the Item's content. So, in a Data Binding, Data Masking or Counter scenarios, they will be processed first and then Expressions will be evaluated as the last step in the label rendering process.
Expression References
- Referencing an Item: To reference the content of a given Item, that Item must be assigned with a unique Name and then the following expression must be used:
[Items!Item_Name]
e.g. if an Item Name is ProductID, then that item content expression would be[Items!ProductID]
- Referencing a Data Field: To reference the content of a data field, the following expression must be used:
[DataFields!DataField_Name]
e.g. if a data field name is ProductDescription, then that data field expression would be[DataFields!ProductDescription]
- Referencing Operators, Variables/Constants and Functions: To reference any supported operator and function, just specify the correct syntax for them. More than 100 built-in functions are provided by default. You can also add Custom Functions and Variables/Constants!
ExpressionBuilder Class
The ExpressionBuilder
class allows you to get the list of built-in Expressions as well as the ability of setting Custom Functions and Variables/Constants. The sample projects shipped in the installer package show how to use ExpressionBuilder class.
Built-in Expressions
The following table lists the built-in Expressions for Operators and Functions:
Category | Name | Syntax | Description | Example |
---|---|---|---|---|
ArithmeticOperators | * | * | Multiplies two numbers. | 2 * 3 [Items!ProductQty] * 3 |
ArithmeticOperators | / | / | Divides two numbers and returns a floating-point result. | 2 / 3 [Items!ProductPrice] / 3 |
ArithmeticOperators | + | + | Adds two numbers. Also used to concatenate two strings. | 2 + 3 [Items!ProductName] + " - " + [Items!ProductModel] |
ArithmeticOperators | - | - | Yields the difference between two numbers or indicates the negative value of a numeric expression. | 5 - 3 -[Items!ProductPrice] |
ComparisonOperators | < | < | Less than. | 2 < 3 [Items!ProductQty] < 3 |
ComparisonOperators | <= | <= | Less than or equal to. | 2 <= 3 [Items!ProductQty] <= 3 |
ComparisonOperators | > | > | Greater than. | 2 > 3 [Items!ProductQty] > 3 |
ComparisonOperators | >= | >= | Greater than or equal to. | 2 >= 3 [Items!ProductQty] >= 3 |
ComparisonOperators | = | = | Equal to. | [Items!ProductQty] = 3 |
ComparisonOperators | <> | <> | Not equal to. | [Items!ProductQty] <> 3 |
ConcatenationOperators | + | + | Adds two numbers. Also used to concatenate two strings. | 2 + 3 [Items!ProductName] + " - " + [Items!ProductModel] |
LogicalOperators | And | (Expr1) And (Expr2) | Performs short-circuiting logical conjunction on two expressions. NOTE: Expressions must be enclosed in parentheses i.e. (Expr1) And (Expr2). | ([Items!ProductQty] = 5) And ([Items!ProductPrice] > 100) |
LogicalOperators | Or | (Expr1) Or (Expr2) | Used to perform short-circuiting logical disjunction on two expressions. NOTE: Expressions must be enclosed in parentheses i.e. (Expr1) Or (Expr2). | ([Items!ProductQty] = 5) Or ([Items!ProductPrice] > 100) |
LogicalOperators | Not | Not (Expr1) | Performs logical negation on a Boolean expression. NOTE: Expression must be enclosed in parentheses i.e. Not (Expr1). | Not ([Items!ProductQty] = 5) |
TextFunctions | Asc | Asc(Str As String) | Returns an integer value representing the character code corresponding to a character. This can be 0 through 255 for single-byte character set (SBCS) values and -32768 through 32767 for double-byte character set (DBCS) values. | Asc(Items!Description) |
TextFunctions | AscW | AscW(Str As String) | Returns an integer value representing the Unicode character code corresponding to a character. This can be 0 through 65535. The returned value is independent of the culture and code page settings for the current thread. | Asc(Items!Description) |
TextFunctions | Chr | Chr(CharCode As Integer) | Returns the character associated with the specified character code. | Chr(65) |
TextFunctions | ChrW | ChrW(CharCode As Integer) | Returns the character associated with the specified Unicode character code. | ChrW(230) |
TextFunctions | Format | Format(Expression As Object, Style As String = "") | Returns a string formatted according to instructions contained in a format String expression. | Format(Now(), "Long Date") or Format(Now(), "D") -> Returns current system date in the system-defined long date format. Format(5459.4, "##,##0.00") -> Returns "5,459.40" |
TextFunctions | FormatCurrency | FormatCurrency(Expression As Object, NumDigitsAfterDecimal As Integer = -1, IncludeLeadingDigit As String = "UseDefault", UseParensForNegativeNumbers As String = "UseDefault", GroupDigits As String = "UseDefault") | Returns an expression formatted as a currency value using the currency symbol defined in the system control panel. | FormatCurrency([Items!ProductPrice], -1, "UseDefault", "UseDefault", "UseDefault") |
TextFunctions | FormatDateTime | FormatDateTime(Expression As DateTime, NamedFormat As String = "GeneralDate") | Returns a string expression representing a date/time value. NamedFormat Values: "GeneralDate", "LongDate", "ShortDate", "LongTime", or "ShortTime" |
FormatDateTime(Now(), "GeneralDate") |
TextFunctions | FormatNumber | FormatNumber(Expression As Object, NumDigitsAfterDecimal As Integer = -1, IncludeLeadingDigit As String = "UseDefault", UseParensForNegativeNumbers As String = "UseDefault", GroupDigits As String = "UseDefault") | Returns an expression formatted as a number. | FormatNumber([Items!ProductPrice], -1, "UseDefault", "UseDefault", "UseDefault") |
TextFunctions | FormatPercent | FormatPercent(Expression As Object, NumDigitsAfterDecimal As Integer = -1, IncludeLeadingDigit As String = "UseDefault", UseParensForNegativeNumbers As String = "UseDefault", GroupDigits As String = "UseDefault") | Returns an expression formatted as a percentage (that is, multiplied by 100) with a trailing % character. | FormatPercent([Items!TotalCarbohydrate], -1, "UseDefault", "UseDefault", "UseDefault") |
TextFunctions | GetChar | GetChar(Str As String, Index As Integer) | Returns a Char value representing the character from the specified (1-based) index in the supplied string. | GetChar([Items!Description], 5) |
TextFunctions | InStr | InStr(str1 As String, str2 As String, StartPos As Integer = -1) | Returns an integer specifying the start position of the first occurrence of one string within another. | InStr([Items!Description], "car", -1) |
TextFunctions | InStrRev | InStrRev(StringCheck As String, StringMatch As String, Start As Integer = -1) | Returns the position of the first occurrence of one string within another, starting from the right side of the string. | InStrRev([Items!Description], "car", -1) |
TextFunctions | LCase | LCase(Str As String) | Returns a string or character converted to lowercase. | LCase([Items!Description]) |
TextFunctions | Left | Left(Str As String, Length As Integer) | Returns a string containing a specified number of characters from the left side of a string. | Left([Items!Description], 5) |
TextFunctions | Len | Len(Str String) | Returns an integer containing either the number of characters in a string. | Len([Items!Description]) |
TextFunctions | LSet | LSet(Str String, Length As Integer) | Returns a left-aligned string containing the specified string adjusted to the specified length. | LSet([Items!Description], 20) |
TextFunctions | LTrim | LTrim(Str As String) | Returns a string containing a copy of a specified string with no leading spaces. | LTrim([Items!Description]) |
TextFunctions | Mid | Mid(Str As String, Start As Integer, Length As Integer) | Returns a string that contains a specified number of characters starting from a specified position in a string. | Mid([Items!Description], 1, 5) |
TextFunctions | Replace | Replace(Expression As String, Find As String, Replacement As String, Start As Integer = 1, Count As Integer = -1) | Returns a string in which a specified substring has been replaced with another substring a specified number of times. | Replace([Items!Description], "tube", "headlight", 1, -1) |
TextFunctions | Right | Right(Str As String, Length As Integer) | Returns a string containing a specified number of characters from the right side of a string. | Right([Items!Description], 5) |
TextFunctions | RSet | RSet(Str As String, Length As Integer) | Returns a right-aligned string containing the specified string adjusted to the specified length. | RSet([Items!Description], 20) |
TextFunctions | RTrim | RTrim(Str As String) | Returns a string containing a copy of a specified string with no trailing spaces. | RTrim([Items!Description]) |
TextFunctions | Space | Space(Number As Integer) | Returns a string consisting of the specified number of spaces. | Space(3) |
TextFunctions | StrDup | StrDup(Number As Integer, Character As String) | Returns a string consisting of the specified character repeated the specified number of times. | StrDup(5, "M") |
TextFunctions | StrReverse | StrReverse(Str As String) | Returns a string in which the character order of a specified string is reversed. | StrReverse([Items!Description]) |
TextFunctions | Trim | Trim(Str As String) | Returns a string containing a copy of a specified string with no leading or trailing spaces. | Trim([Items!Description]) |
TextFunctions | UCase | UCase(Str As String) | Returns a string or character converted to uppercase. | UCase([Items!Description]) |
DateTimeFunctions | CDate | CDate(val As Object) | Convert to DateTime. | CDate([Items!ExpiryDate]) |
DateTimeFunctions | DateAdd | DateAdd(Interval As String, Number As Double, DateValue As DateTime) | Returns a Date value containing a date and time value to which a specified time interval has been added. Interval Values: "Year", "Quarter", "Month", "DayOfYear", "Day", "WeekOfYear", "Weekday", "Hour", "Minute", or "Second" |
DateAdd("Month",3,CDate([Items!ExpiryDate])) |
DateTimeFunctions | DateDiff | DateDiff(Interval As String, Date1 As DateTime, Date2 As DateTime, DayOfWeek As String = "Sunday", WeekOfYear As String = "Jan1") | Returns a Long value specifying the number of time intervals between two Date values. Interval Values: "Year", "Quarter", "Month", "DayOfYear", "Day", "WeekOfYear", "Weekday", "Hour", "Minute", or "Second" DayOfWeek Values: "System", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" WeekOfYear Values: "System", "Jan1", "FirstFourDays", "FirstFullWeek" |
DateDiff("Year",CDate([Items!ExpiryDate]),"1/1/2010", "Sunday", "Jan1") |
DateTimeFunctions | DatePart | DatePart(Interval As String, DateValue As DateTime, DayOfWeek As String = "Sunday", WeekOfYear As String = "Jan1") | Returns an Integer value containing the specified component of a given Date value. Interval Values: "Year", "Quarter", "Month", "DayOfYear", "Day", "WeekOfYear", "Weekday", "Hour", "Minute", or "Second" DayOfWeek Values: "System", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" WeekOfYear Values: "System", "Jan1", "FirstFourDays", "FirstFullWeek" |
DatePart("Quarter", CDate([Items!ExpiryDate]), "Sunday", "Jan1") |
DateTimeFunctions | DateSerial | DateSerial(Year As Integer, Month As Integer, Day As Integer) | Returns a Date value representing a specified year, month, and day, with the time information set to midnight (00:00:00). | DateSerial(2019,10,24) |
DateTimeFunctions | DateString | DateString() | Returns a String value representing the current date according to your system. | DateString() |
DateTimeFunctions | DateValue | DateValue(StringDate As String) | Returns a Date value containing the date information represented by a string, with the time information set to midnight (00:00:00). | DateValue("February 12, 2018") |
DateTimeFunctions | Day | Day(DateValue As DateTime) | Returns an Integer value from 1 through 31 representing the day of the month. | Day(CDate([Items!ExpiryDate])) |
DateTimeFunctions | Hour | Hour(TimeValue As DateTime) | Returns an Integer value from 0 through 23 representing the hour of the day. | Hour(Now()) |
DateTimeFunctions | Minute | Minute(TimeValue As DateTime) | Returns an Integer value from 0 through 59 representing the minute of the hour. | Minute(Now()) |
DateTimeFunctions | Month | Month(DateValue As DateTime) | Returns an Integer value from 1 through 12 representing the month of the year. | Month(Now()) |
DateTimeFunctions | MonthName | MonthName(Month As Integer, Abbreviate As Boolean = false) | Returns a String value containing the name of the specified month. | MonthName(10, False) |
DateTimeFunctions | Now | Now() | Returns a DateTime value containing the current date and time according to the system. | Now() |
DateTimeFunctions | Second | Second(TimeValue As DateTime) | Returns an Integer value from 0 through 59 representing the second of the minute. | Second(Now()) |
DateTimeFunctions | TimeOfDay | TimeOfDay() | Returns or sets a Date value containing the current time of day according to your system. | TimeOfDay() |
DateTimeFunctions | Timer | Timer() | Returns a Double value representing the number of seconds elapsed since midnight. | Timer() |
DateTimeFunctions | TimeSerial | TimeSerial(Hour As Integer, Minute As Integer, Second As Integer) | Returns a Date value representing a specified hour, minute, and second, with the date information set relative to January 1 of the year 1. | TimeSerial(23,49,52) |
DateTimeFunctions | TimeString | TimeString() | Returns or sets a String value representing the current time of day according to your system. | TimeString() |
DateTimeFunctions | TimeValue | TimeValue(StringTime As String) | Returns a Date value containing the time information represented by a string, with the date information set to January 1 of the year 1. | TimeValue("16:20:17") |
DateTimeFunctions | Today | Today() | Returns or sets a Date value containing the current date according to your system. | Today() |
DateTimeFunctions | Weekday | Weekday(DateValue As DateTime, DayOfWeek As String = "Sunday") | Returns a Long value specifying the number of time intervals between two Date values. DayOfWeek Values: "System", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" |
Weekday(CDate([Items!ExpiryDate]), "Sunday") |
DateTimeFunctions | WeekdayName | WeekdayName(Weekday As Integer, Abbreviate As Boolean = false, FirstDayOfWeekValue As String = "System") | Returns a String value containing the name of the specified weekday. FirstDayOfWeek Values: "System", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" |
WeekdayName(2, False, "System") |
DateTimeFunctions | Year | Year(DateValue As DateTime) | Returns an Integer value from 1 through 9999 representing the year. | Year(Now()) |
MathFunctions | Abs | Abs(value As Single) | Returns the absolute value of a single - precision floating - point number. | Abs(-5.5) |
MathFunctions | Acos | Acos(value As Double) | Returns the angle whose cosine is the specified number. | Acos(.5) |
MathFunctions | Asin | Asin(value As Double) | Returns the angle whose sine is the specified number. | Asin(.5) |
MathFunctions | Atan | Atan(value As Double) | Returns the angle whose tangent is the specified number. | Atan(45) |
MathFunctions | Atan2 | Atan2(y As Double, x As Double) | Returns the angle whose tangent is the quotient of two specified numbers. | Atan2(3,5) |
MathFunctions | BigMul | BigMul(a As Integer, b As Integer) | Produces the full product of two 32-bit numbers. | BigMul(2147483647,-2147483647) |
MathFunctions | Ceiling | Ceiling(value As Double) | Returns the smallest integer greater than or equal to the specified double-precision floating-point number. | Ceiling(34.3352) |
MathFunctions | Cos | Cos(value As Double) | Returns the cosine of the specified angle. | Cos(67) |
MathFunctions | Cosh | Cosh(value As Double) | Returns the hyperbolic cosine of the specified angle. | Cosh(67) |
MathFunctions | Exp | Exp(value As Double) | Returns e raised to the specified power. | Exp(5) |
MathFunctions | Fix | Fix(value As Double) | Return the integer portion of a number. | Fix(-9.25) |
MathFunctions | Floor | Floor(value As Double) | Returns the largest integer less than or equal to the specified double-precision floating-point number. | Floor(4.67) |
MathFunctions | Int | Int(value As Double) | Returns the integer portion of the specified double-precision floating-point number. | Int(4.67) |
MathFunctions | IntDiv | IntDiv(Dividend As Object, Divisor As Object) | Divides two numbers and returns an integer result. | IntDiv(11, 4) |
MathFunctions | Log | Log(value As Double) | Returns the natural (base e) logarithm of a specified number. | Log(33.5) |
MathFunctions | Log10 | Log10(value As Double) | Returns the base 10 logarithm of a specified number. | Log10(33.5) |
MathFunctions | Max | Max(val1 As Double, val2 As Double) | Returns the larger of two double-precision floating-point numbers. | Max(33.5, 10.2) |
MathFunctions | Min | Min(val1 As Double, val2 As Double) | Returns the smaller of two double-precision floating-point numbers. | Min(33.5, 10.2) |
MathFunctions | Mod | Mod(Dividend As Object, Divisor As Object) | Divides two numbers and returns only the remainder as a double-precision floating-point number. | Mod(11, 4) |
MathFunctions | Pow | Pow(x As Double, y As Double) | Returns the smaller of two double-precision floating-point numbers. | Pow(3,2) |
MathFunctions | Round | Round(val As Double) | Rounds a double-precision floating-point value to the nearest integral value, and rounds midpoint values to the nearest even number. | Round(3.75) |
MathFunctions | Sin | Sin(value As Double) | Returns the sine of the specified angle. | Sin(67) |
MathFunctions | Sinh | Sinh(value As Double) | Returns the hyperbolic sine of the specified angle. | Sinh(67) |
MathFunctions | Sqrt | Sqrt(value As Double) | Returns the square root of a specified number. | Sqrt(144) |
MathFunctions | Tan | Tan(value As Double) | Returns the tangent of the specified angle. | Tan(135) |
MathFunctions | Tanh | Tanh(value As Double) | Returns the hyperbolic tangent of the specified angle. | Tanh(135) |
InspectionFunctions | IsDate | IsDate(Str As String) | Returns a Boolean value indicating whether a string represents a valid Date value. | IsDate([Items!ExpiryDate]) |
InspectionFunctions | IsNothing | IsNothing(val As Object) | Returns a Boolean value indicating whether an expression has no object assigned to it. | IsNothing([Items!ProductName]) |
InspectionFunctions | IsNumeric | IsNumeric(Str As String) | Returns a Boolean value indicating whether a string represents a valid Numeric value. | IsNumeric([Items!ProductPrice]) |
ProgramFlowFunctions | IIf | IIf(Expression As Boolean, TruePart As Object, FalsePart As Object) | Returns one of two objects, depending on the evaluation of an expression. | IIf([Items!ProductPrice] >= 60000,"High","Low") |
ConversionFunctions | CBool | CBool(val As Object) | Convert to Boolean. | CBool([Items!ProdContainsTransFat]) |
ConversionFunctions | CByte | CByte(val As Object) | Convert to Byte. | CByte([Items!ServingsPerContainer]) |
ConversionFunctions | CChar | CChar(val As Object) | Convert to Char. | CChar([Items!EnergyEfficientLevel]) |
ConversionFunctions | CDate | CDate(val As Object) | Convert to DateTime. | CDate([Items!ExpiryDate]) |
ConversionFunctions | CDbl | CDbl(val As Object) | Convert to Double. | CDbl([Items!ProductPrice]) |
ConversionFunctions | CDec | CDec(val As Object) | Convert to Decimal. | CDec([Items!ProductPrice]) |
ConversionFunctions | CInt | CInt(val As Object) | Convert to Integer. | CInt([Items!ProductQty]) |
ConversionFunctions | CLng | CLng(val As Object) | Convert to Long. | CLng([Items!ProductQty]) |
ConversionFunctions | CShort | CShort(val As Object) | Convert to Short. | CShort([Items!ProductQty]) |
ConversionFunctions | CSng | CSng(val As Object) | Convert to Single. | CSng([Items!ProductPrice]) |
ConversionFunctions | CStr | CStr(val As Object) | Convert to String. | CStr([Items!ProductPrice]) |
ConversionFunctions | Fix | Fix(value As Double) | Return the integer portion of a number. | Fix(-9.25) |
ConversionFunctions | Hex | Hex(val As Object) | Returns a string representing the hexadecimal value of a number. | Hex([Items!ProductSerialNumber]) |
ConversionFunctions | Int | Int(value As Double) | Returns the integer portionof the specified double-precision floating-point number. | Int(4.67) |
ConversionFunctions | Oct | Oct(val As Object) | Returns a string representing the octal value of a number. | Hex([Items!ProductSerialNumber]) |
BarcodeFunctions | GetAustraliaPost4StateBarcodeChecksum | GetAustraliaPost4StateBarcodeChecksum(Code As String) | Returns the checksum (Reed Solomon codewords) for an Australia Post 4 State code. | GetAustraliaPost4StateBarcodeChecksum("1139987520") |
BarcodeFunctions | GetAustraliaPostDomesticEParcelChecksum | GetAustraliaPostDomesticEParcelChecksum(Code As String) | Returns the checksum integer number for an Australia Post Domestic eParcel code. | GetAustraliaPostDomesticEParcelChecksum("99700160DJS123456701021502000") |
BarcodeFunctions | GetCode39Checksum | GetCode39Checksum(Code As String) | Returns the checksum Modulus 43 used by Code 39 barcode. | GetCode39Checksum("ABC123") |
BarcodeFunctions | GetCode93Checksum | GetCode93Checksum(Code As String) | Returns the two-char checksum Modulus 47 used by Code 93 barcode. | GetCode93Checksum("ABC123") |
BarcodeFunctions | GetDeutschePostModulus11Checksum | GetDeutschePostModulus11Checksum(Code As String) | Returns the checksum integer number for a valid 8-digit Deutsche Post Ident code. | GetDeutschePostModulus11Checksum("56400000005") |
BarcodeFunctions | GetDhlAwbChecksum | GetDhlAwbChecksum(Code As String) | Returns the checksum integer number Modulus 7 used by DHL AWB barcode. | GetDhlAwbChecksum("56400000005") |
BarcodeFunctions | GetModulus10Checksum | GetModulus10Checksum(Code As String) | Returns the checksum integer number Modulus 10. | GetModulus10Checksum("123456789") |
BarcodeFunctions | GetPpnChecksum | GetPpnChecksum(Code As String) | Returns the 2-digit checksum Modulus 97 used by IFA PPN barcode. | GetPpnChecksum("03752864") |
BarcodeFunctions | GetVoicePickCode | GetVoicePickCode(Code As String) | Returns a 4 digit Voice Pick Code from specified GTIN, lot, and optional pack date. | GetVoicePickCode("10850510002011" + "46587443HG234") Where: GTIN = (01)10850510002011 Lot = (10)46587443HG234 |
BarcodeFunctions | IsGS1DataValid | IsGS1DataValid(Code As String) | Returns true if the specified string is compliance with the GS1 General Specifications rules; otherwise it returns false. | IsGS1DataValid("(01)10850510002011") |
Variables | PAGE_NUMBER | PAGE_NUMBER | Returns the current page number. | PAGE_NUMBER |
Variables | TOTAL_PAGES | TOTAL_PAGES | Returns the total number fof pages in the current continous page sequence. | TOTAL_PAGES |