Formula Data Source Operations and Functions
The following tables describe the operations and functions that you can use when creating formulas.
In this table, input refers to a field name, data source, or data service parameter.
Tip: For string concatenation, use the + operator. Note that & is not a valid concatenation operator.
Formula Data Source Operations
Operation |
Description |
Syntax |
---|---|---|
+ |
Adds numeric values or concatenates string values. If the values provided are numbers, then the values are added. If the values provided are strings, then the values are concatenated. (1 * {/Body/Text1}) + (1 * {/Body/Text2}) results in numeric addition. {/Body/Text1} + {/Body/Text2} results in string concatenation. 1 + {/Body/Text1} results in numeric addition. {/Body/Text1} + 2 results in string concatenation. num({/Body/Text1}) + num({/Body/Text2}) results in numeric addition. "" + 1 + 2 results in string concatenation. |
<input1> + <input2> Example In the following formula, Text1 and Text2 are interpreted as string values. If Text1=1 and Text2=2, then the result is 12. {/Body/Text1} + {/Body/Text2} In the following formula, the values are interpreted as numbers. If Text1=1 and Text2=2, then the result is 3. num({/Body/Text1}) + num({/Body/Text2}) |
- |
Subtracts numeric values. |
<input1> - <input2> Example {/Body/Text01} - {/Body/Text02} |
* |
Multiplies numeric values. |
<input1> * <input2> Example {/Body/Text01} * {/Body/Text02} |
/ |
Divides numeric values. |
<input1> / <input2> Example {/Body/Text01} / {/Body/Text02} |
% |
Returns the remainder of the division of two numeric values (modulus). |
<input1> % <input2> Example {/Body/Text01} % {/Body/Text02} |
Parentheses |
Group values resulting from one or more operations. |
() Example ({/Body/Text01} + {/Body/Text02}) * 2 |
Fixed String |
Enclose a fixed string value. |
"<fixed_string>" Example "Expiration Date: " + {/Body/Text01} |
Trim |
Removes the character specified in parentheses and quotation marks from both the left and the right of the input. If no character is supplied .trim removes spaces from the left side and right side of the input. |
<input>.trim("<trim_char>") Example This formula removes all consecutive occurrences of the character 0 from both sides of the input. If Text3=010100, then the result is 101. {/Body/Text3}.trim("0") |
Left-Trim |
Removes the character specified in parentheses and quotation marks from the left of the input. If no character is supplied, .ltrim will strip spaces from the left side of the input. |
<input>.ltrim("<trim_char>") Example This formula removes all consecutive occurrences of the character 0 from the leftmost side of the input. If Text3=010100, then the result is 10100. {/Body/Text3}.ltrim("0") |
Right-Trim |
Removes the character specified in parentheses and quotation marks from the right side of the input. If no character is supplied, .rtrim will strip spaces from the right side of the input. |
<input>.rtrim("<trim_char>") Example This formula removes all consecutive occurrences of the character 0 from the rightmost side of the input. If Text3=010100, then the result is 0101. {/Body/Text3}.rtrim("0") |
Left-Pad |
Adds the character specified in parentheses and quotation marks onto the left side of the of the input until the result has the length specified after the comma. |
<input>.lpad("<pad_char>",<length>) Example This formula adds zeros to the left side of the input until the total length is 10 characters. If DS_0000=12345678, then the result is 0012345678. {/DS_0000}.lpad("0",10) |
Right-Pad |
Adds the character specified in parentheses and quotation marks onto the right side of the input string until the result has the length specified after the comma. |
<input>.rpad("<pad_char>",<length>) Example This formula adds zeros to the right side of the input until the total length is 10 characters. If DS_0000=12345678, then the result is 1234567800. {/DS_0000}.rpad("0",10) |
Left-String |
Returns the number of characters specified in parentheses from the left side of the input string. |
<input>.lstr(<length>) Example This formula returns the first three characters from the left side of the input. If DS_0001=12345, then the result is 123. {/DS_0001}.lstr(3) |
Right-String |
Returns the number of characters specified in parentheses from the right side of the input string. |
<input>.rstr(<length>) Example This formula returns the first three characters from the right side of the input. If DS_0001=12345, then the result is 345. {/DS_0001}.rstr(3) |
Mid-String |
Returns a substring, starting at <position>, with the length of <number_of_chars>. The index count for <position> begins at 1. |
<input>.midstr(<position>,<number_of_chars>) Example This formula returns the second and third characters. If DS_0004=ABCDE, then the result is BC. {/DS_0004}.midstr(2,2) |
Spaces |
Returns a string, repeated a specified number of times. If the input string is not specified, the default value of a single space is used and the specified number of spaces is returned. |
spaces(<number_of_strings>,<input>) Example This formula returns three of the string specified in the Text4 prompt. If Text4=0, then the result is 000. spaces(3,{/Body/Text4}) |
inString |
Returns the index of the specified occurrence of the specified substring within the input string, or -1 if the substring is not found. The search begins at the position of the start index and moves in the direction specified. The index count begins at 1, representing the position of the character at beginning of the string, regardless of the start index for the search. The direction determines at which end of the string the index count begins. For the direction, 0 indicates left to right, and any number greater than zero indicates right to left. The start index, occurrence, and direction values are optional. If they are omitted, the following default values are used:
|
<input>.inString(<substring_to_find>, <start_index>, <occurrence>, <direction>) Example This formula searches the string named Text5 from left to right, beginning with the fourth character. It returns the numerical position of the second occurrence of the substring AB. If Text5=ABCDEFGABCAB, then the result is 11. {/Body/Text5}.inString("AB",4,2,0) |
Length |
Returns the number of characters in the string. |
<input>.length Example For this formula, if Text6=A1BC2, then the result is 5. {/Body/Text6}.length |
Num |
Forces a string containing only numeric characters to be interpreted as a number. To produce expected results, the string should include only numeric data. |
num(<input>) Example For this formula, if Text1=1 and Text2=2, then the result is 3. num({/Body/Text1}) + num({/Body/Text2}) |
Formula Data Source Functions
Function |
Description |
Syntax |
---|---|---|
Duplicates |
The formula uses the number of duplicate labels to be printed, entered at print time, as its data. |
COPIES() |
Quantity of Labels |
The formula uses the number of labels to be printed, entered at print time, as its data. Example In conjunction with an incrementing field, you can use this feature to build a label counter (For example, 1 of 5, 2 of 5) where the "of" count automatically matches the number of labels printed. |
QTY() |
ASCII Character |
Inserts the ASCII character for the decimal value specified. |
ASCII_CHAR(<input>) |
ASCII BEL |
Inserts an audible alert (bell) character. |
ASCII_BEL() |
ASCII CR |
Inserts a carriage return. |
ASCII_CR() |
ASCII CRLF |
Inserts a carriage return line feed. |
ASCII_CRLF() |
ASCII EOT |
Inserts an end of transmission. |
ASCII_EOT() |
ASCII FF |
Inserts a form feed. |
ASCII_FF() |
ASCII FS |
Inserts a file separator character, common in Maxi-Code. |
ASCII_FS() |
ASCII GS |
Inserts a group separator character, common in Maxi-Code. |
ASCII_GS() |
ASCII HT |
Inserts a tab character. |
ASCII_HT() |
ASCII LF |
Inserts a line feed. |
ASCII_LF() |
ASCII RS |
Inserts a record separator character. |
ASCII_RS() |
ASCII SO |
Inserts a Shift Out character to extend the graphic character set. |
ASCII_SO() |
ASCII US |
Inserts a unit separator character. |
ASCII_US() |
FNC1 |
Inserts a Function 1 symbol character into the barcode. |
FNC1() |
FNC2 |
Inserts a Function 2 symbol character into the barcode. |
FNC2() |
FNC3 |
Inserts a Function 3 symbol character into the barcode. |
FNC3() |
FNC4 |
Inserts a Function 4 symbol character into the barcode. |
FNC4() |
Code 128:Shift |
Inserts a Code 128 Shift character for switching subsets. |
SHIFT() |
Code 128:Code A |
Changes to Code A for processing the portion of the barcode that follows. Code A can include upper case alphabetic characters, numeric characters, and ASCII function calls. |
CODEA() |
Code 128:Code B |
Changes to Code B for processing the portion of the barcode that follows. Code B can include upper and lower case alphanumeric characters. |
CODEB() |
Code 128:Code C |
Changes to Code C for processing the portion of the barcode that follows. Code C can include numeric characters only. |
CODEC() |
Code 128:Code GS1 |
Makes a standard Code 128 barcode and inserts a Function 1 symbol character. |
CODEGS1() |
Composite Delimiter |
Inserts a vertical bar character that should be used to separate the 2D portion and the linear portion in the data for a composite barcode. |
COMPDELIM() |
Mod 10 |
Inserts a Modulus 10 check character based on numeric input enclosed in parentheses. Note: The length parameter is optional. |
Mod10(<length>,<input>) |
Mod 43 |
Inserts a Modulus 43 check character based on the input enclosed in parentheses. Note: The length parameter is optional. |
Mod43(<length>,<input>) |
Mod 7 |
Inserts a Modulus 7 check character based on numeric input enclosed in parentheses. Note: The length parameter is optional. |
Mod7(<length>,<input>) |
GS1 Mod 10 |
Inserts a Modulus 10 check character based on numeric input enclosed in parentheses. The result is the same regardless of whether the Application Identifier is included in the input. Note: The length parameter is optional. |
GS1Mod10(<length>,<input>) |
Formula Evaluation
The Formula Evaluation option allows you to select select whether to use Loftware or the Device to resolve the formula. This option only applies if you are using a Loftware device. For more information, see Using a Loftware NiceLabel Driver.