Expressions can be comprised of: numbers, strings, booleans, or objects. You can also use lists of these data types, called arrays. For more information on arrays, see Chapter 27: Using arrays.
A number can be an integer, a floating-point, or a hexadecimal number.
Data type |
Description |
Integer¹ |
An integer is composed of one or many decimal-digits (0 through 9). |
Floating-point¹ |
A floating-point is composed of zero or many decimal-digits (0 through 9) followed by a decimal and, optionally one or many decimal-digits. For example, 1., 2., 123., .7, 8.5, and 123.45 are all floating-points. |
Hexadecimal number |
A hexadecimal number is composed of 0x (or 0X) followed by one or many hex-digits (0 through 9 followed by the letters A through F). Note that there is a difference between the numerical representation (prefix = 0x) and the literal string representation (prefix = x) which must have 2 leading zeros following the prefix. |
¹ Both integers and floating-point numbers can be written using scientific notation, that is the number can be followed by the letter E (e or E), a plus (+), a minus (-), and one or many decimal-digit, for example: 10e-2, 1.e+3, .7e5, and 8.5e-5 are all numbers written using scientific notation.
When an input only accepts an integer value (for example, the ResetValue property of the Counter step) and a floating-point value is entered, it will be rounded to the nearest integer. If the value is midway between 2 other numbers, it is rounded toward the nearest number that is away from zero.
Strings are a concatenation of sequences of Unicode characters, escape sequences, inline expressions, and formatting codes. Text entered in a string-type input is always interpreted as a literal string, unless it is enclosed in the evaluate-to-string operator ({}), in which case it will be evaluated as an inline expression.
In some cases, one or more characters following a backslash (\) have special meaning. The following is a complete list of valid escape sequences:
Escape sequence |
Meaning |
\' |
Single quote. |
\\ |
Backslash. |
\0 |
Null. |
\a |
Alert (bell character). |
\b |
Backspace. |
\f |
Form feed. |
\n |
New line. |
\r |
Carriage return. |
\t |
Horizontal tab. |
\v |
Vertical tab. |
\xnnnn |
Hexadecimal values in a string. |
Note that if you need an ASCII control character not in this list, such as the Esc character, you should specify the hex code explicitly following the backslash. Hex codes should have 4 characters, (for example, the hex code for the character "[" is \x005B).
Strings can be wholly or partially constructed from inline expressions using the evaluate-to-string operator ({}). Text within the evaluate-to-string operator ({}) will be evaluated as an expression. For example, the following text will be evaluated literally if used in a string-type input:
This input will be evaluated as the string "The number (TOSTRING(ABS(Variables.aGreatNumber))) is positive".
If the function calls are instead enclosed in the evaluate-to-string operator ({}), they will be evaluated as an expression. For example, if Variables.aGreatNumber is -5, the following text will incorporate that value:
This input will be evaluated as the string "The number 5 is positive".
Within an expression, any text that must be evaluated as a string must be enclosed in quotation marks (""). For example, the PATH function takes a string as a parameter. The following text will produce a error:
To resolve this error, the parameter must be enclosed in quotation marks (""):
To initialize an array of characters or strings, each element must separated by a comma (,), the set of elements must be enclosed in the array operator ([]), and the entire array must be enclosed in the evaluate-to-string operator ({}). Text that should not be evaluated as an expression must be enclosed in quotation marks (""); for example, an array of the first 4 letters of the alphabet would be initialized with:
Formatting codes can be used to control how a numerical value enclosed in the evaluate-to-string operator ({}) will be displayed when converted to a string. Formatting codes must be written after a comma at the end of the expression being evaluated. Unlike formatting codes used with the TOSTRING function, formatting codes used with the evaluate-to-string operator ({}) must not be enclosed in quotation marks (""). For example, the following expression will be evaluated as "24.98":
In this case, the formatting code specifies that the result of the inline expression should be rounded to 2 decimal characters. You can also produce a string with leading or trailing zeros by specifying a custom layout of :00.00, where the number of zeroes before and after the decimal point equals the number of digits to be displayed. For more information about formatting codes, see the User-defined date/time and number formats section in Appendix A: Expression syntax.
Boolean variables can only take on the following values:
0 (false).
1 (true).
A complex expression can be inserted wherever a boolean could be taken as an input. A complex expression contains one or more operators, functions, or links. If the complex expression evaluates to a value different than 0, the input equals to true. Boolean inputs also accept comparisons. See the Comparisons section in Appendix A: Expression syntax for more information.
Objects are a complex data type that might include several of the other data types. Results of analysis steps often return results as objects.
Objects can be given as inputs, in which case they must be passed as single values or links; for example the SearchRegion of the CodeReader step, or Trigger of the Camera step.
For more information about using an array of objects, see the Using object arrays section in Chapter 27: Using arrays. For information about how to output results in a certain format, see the User-defined date/time and number formats section in Appendix A: Expression syntax.
When you add a variable of type step, you must specify an Object type, which must be a type of step that is in your project. You can then set the step variable's Initial value to a specific step of that type. For example, if your project has multiple IntensityChecker steps, you can set Object type to IntensityChecker and Initial value to the specific intensity checker step. A reference to the specified step is stored in the variable. Note that you can also store a step in a variable using the store step.
You can link to the inputs and output of the step stored in the variable. These inputs and outputs are available for the variable in the tree structure. Step-type variables support the general features of variables, such as binding and persistence.
Step-type variables can simplify your code considerably. For an example, refer to the Presence Absence template project, available from the Matrox Design Assistant Quick Start tab. Here, the user can select from one of 16 regions in which to apply an intensity check. Rather that having that input handled 16 different times, it is handled once by an IntensityChecker step variable.