How To Construct Logic Expressions

Logic expressions represent true or false circumstances. Logic expressions typically consist of at least two arguments (usually value expressions) combined using conditional operators (conditional expressions), Boolean operators (Boolean expressions), or both. Logic expressions can be quite complex. Parentheses can be used to explicitly control the order of evaluation in complex logic expressions.

When a statement contains a logic expression, the software evaluates the expression to determine if it is logically true or logically false.

Writing Expressions

The conditional operators, Boolean operators, and parentheses can be combined to create long, complex expressions. These logic expressions are evaluated based on the standard rules of precedence. Parentheses alter the order of evaluation.

Spaces between operands and symbol operators can be used for clarity, but are not required; spaces must appear, however, between operands and word operators.

For example, Salary > 20000 and Salary>20000 are equivalent, but notSalary>45000 cannot be substituted for not Salary>45000.

Data Types

Logic expressions always yield a logical true/false result.

The operands used in any single conditional expression should preferably be of the same data type; however, non-matching types are converted, if necessary, to perform the comparison specified by the operator. The operands used in any single Boolean expression must have logic values (i.e., their values must be logical true/false).

Pattern Matching In Conditional Expressions

The conditional operators LIKE and = (equals) can be used with special wildcard characters to perform pattern matching of character strings.

The available LIKE wildcards are

_ (underscore)

The underscore matches any single character.

% (percent sign)

The percent character matches any sequence of zero or more characters.

\ (escape character)

The backslash indicates that the next character (usually the underscore or percent sign) is to be taken literally. However, because a backslash is also used as the software's universal escape operator in character strings, the LIKE backslash must itself be preceded by an escape backslash as shown in the following example:

find Parts where PartNo like "_ _\\_%"

Examples of Pattern Matching in = Logic Expressions

DeptNum = "D56"?

Logically true if the department number begins with the characters D56. Note that the question mark must appear outside the string.

RemarkField = "Smith?"

Shows the question mark being used literally in a string. (The characters appear inside the quotation marks.) The expression is logically true only if Remarkfield contains the exact characters Smith?.

Surname = fCustomer.LastName?

Shows how the wildcard can be attached directly to an atomic expression employing a variable, local variable, form field, or formal parameter, provided the object is of a character data type. (Trailing blanks in the specified object are trimmed for pattern-matching purposes.)

Examples of Pattern Matching in LIKE Logic Expressions

"_ob%"

Matches any character string whose second and third letters are ob, followed by zero or more characters (i.e., "Robert", "Bob", "Cobbler", etc.).

Grade like "100\\%"

Shows the percent sign being used literally in a string. (The first backslash "escapes" the second backslash, which, in turn, "escapes" the percent sign, turning it into a literal character.)

FirstName like $concat("S_e%p",SuffixVariable)

Assuming that SuffixVariable is "%", the above expression is logically true if FirstName matches the pattern S_e%p%.