Skip to content

Expression Syntax

Expression Body Values

Expressions are written by enclosing an expression body inside parentheses (). The following table lists the valid expression body values:

Expression Body Example
Operand X
Unary operator followed by an operand –X
Binary operator between two operands X / Y

Operands

An operand can be any of the following items:

Operand Example
Number 100
String "Hello"
Date 01/01/2000
Constant C_Maximum
Variable iCount
Function call Length("Hello")
Expression Body X + Y
Expression (X + Y)

Operators

Operators are categorized into several groups depending upon the type of expression. The table below lists all the possible operators:

Binary Arithmetic Operators

Operation Description
+ Addition
- Subtraction
* Multiplication
/ Division
^ Power of
Max Maximum
Min Minimum

Unary Arithmetic Operator

Operation Description
- Sign negation

Relational Operators

Operation Description
= Equal
<> Not equal
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
Contains Member of
Matches String compare with wildcards

Boolean Operators

Operation Description
Not Negation
And Logical and
Or Logical or

String Operators

Operation Description
+ Concatenation
- Trim "outer" spaces and concatenate
* Concatenate with a single space between arguments

Bitwise Operators

Operation Description
Iand Bitwise and
Ior Bitwise or

Examples

Here are some examples of expressions:

While ((iTime < 12) and not((sDay = "Sat") or (sDay = "Sun")))
    //…

This is a Boolean expression that would return True if the variables iTime and sDay were set to a weekday before 12pm.

Move (sLastName + ', ' + sFirstName + ' ' + sInitial) To sFullName

This is a string expression that concatenates two string variables with some string constants.

String sFirst sLast sName
Move "    Joe    " to sFirst
Move "    Smith    " to sLast
Move (sFirst - sLast) to sName

This is a string expression that concatenates two string variables using the - operator, which trims all trailing spaces from the first argument and all leading spaces from the second argument, resulting in "JoeSmith" stored in sName.

String sFirst sLast sName
Move "    Joe    " to sFirst
Move "    Smith    " to sLast
Move (sFirst * sLast) to sName

This is a string expression that concatenates two string variables using the * operator, which trims all trailing spaces from the first argument and all leading spaces from the second argument, leaving only a single space between the two strings, resulting in "Joe Smith" stored in sName.

Results of Expressions That Trigger Errors are Undefined

If an expression triggers an error, the result of that expression is undefined and therefore unreliable.

For example, the below expression will trigger an "invalid symbol in expression" error, since the string constant "Fred" cannot be converted to a number. Thus, the contents of variable nValue are undefined after the expression returns and should not be used.

Number nValue
Move "Fred" to nValue

Boolean Expressions

Boolean expressions are evaluated to a result of True or False. In DataFlex, any non-zero integer value can represent the Boolean value of True. The integer 0 represents the Boolean value of `False.

True < > 0
False = 0

Expressions are evaluated left to right. DataFlex performs short-circuit evaluation of Boolean expressions. This means that if the outcome of the entire Boolean expression can be determined by only evaluating part of it, then the outcome is returned without evaluating the rest of the expression. This can occur with Boolean and and or operators as demonstrated in the following examples:

If ((iValueX = 1) or (iValueY = 2)) BeginIf ((iValueX = 1) and (iValueY = 2)) Begin

In the first example, if (iValueX = 1) is true, then (iValueY = 2) is not evaluated because regardless of the outcome, the entire expression will still evaluate to true. The same is true for the second example if (iValueX = 1) is false.

You must be aware of short-circuit evaluation when your expression contains a function call, as in the following example:

If ((iValueX = 1) or (GetNextCharacter() = 'X')) Begin

In this example, the function GetNextCharacter is never executed if (iValueX = 1) is true. If it is important that the GetNextCharacter function is executed, then you should rewrite the expression in the following way:

Move (GetNextCharacter()) To sCharacter
If ((iValueX = 1) or (sCharacter = 'X')) Begin

Special Note

DataFlex expressions do not follow any rules of precedence among operators. You must use parentheses to force precedence. For example:

(1 + 2 * 4)

Should be written as:

(1 + (2 * 4))

If you want the 2 * 4 part to be evaluated before adding one. DataFlex would evaluate the first example as 12 and the second as 9.