About simple expressionsIn their most basic form, FormCalc expressions
are groups of operators, keywords, and literals strung together
in logical ways. For example, these are all simple expressions:
2
"abc"
2 - 3 * 10 / 2 + 7
Each FormCalc expression resolves
to a single value by following a traditional order of operations,
even if that order is not always obvious from the expression syntax.
For example, the following sets of expressions, when applied to
objects on a form design, produce equivalent results:
Expression
|
Equivalent to
|
Returns
|
"abc"
|
"abc"
|
abc
|
2 - 3 * 10 / 2 + 7
|
2 - (3 * (10 / 2)) + 7
|
-6
|
10 * 3 + 5 * 4
|
(10 * 3) + (5 * 4)
|
50
|
0 and 1 or 2 > 1
|
(0 and 1) or (2 >1)
|
1 (true)
|
2 < 3 not 1 == 1
|
(2 < 3) not (1 == 1)
|
0 (false)
|
As the previous table suggests, all FormCalc
operators carry a certain precedence when they appear within expressions.
The following table illustrates this operator hierarchy:
Precedence
|
Operator
|
Highest
|
=
|
|
(Unary) - , + , not
|
|
* , /
|
|
+ , -
|
|
< , <= , > , >= , lt , le ,
gt , ge
|
|
== , <> , eq , ne
|
|
& , and
|
Lowest
|
| , or
|
Promoting operandsIn cases where one or more of the operands
within a given operation do not match the expected type for that
operation, FormCalc promotes the operands to match the required
type. How this promotion occurs depends on the type of operand required
by the operation.
Numeric operationsWhen performing numeric operations involving
non-numeric operands, the non-numeric operands are first promoted
to their numeric equivalent. If the non-numeric operand does not
successfully convert to a numeric value, its value is 0. When promoting
null-valued operands to numbers, their value is always zero.
The
following table provides some examples of promoting non-numeric operands:
Expression
|
Equivalent to
|
Returns
|
(5 - "abc") * 3
|
(5 - 0) * 3
|
15
|
"100" / 10e1
|
100 / 10e1
|
1
|
5 + null + 3
|
5 + 0 + 3
|
8
|
Boolean operationsWhen performing Boolean operations on non-Boolean
operands, the non-Boolean operands are first promoted to their Boolean
equivalent. If the non-Boolean operand does not successfully convert
to a nonzero value, its value is true (1); otherwise its value is
false (0). When promoting null-valued operands to a Boolean value,
that value is always false (0). For example, the expression:
"abc" | 2
evaluates
to 1. That is, false | true = true, whereas
if ("abc") then
10
else
20
endif
evaluates to 20.
String operationsWhen performing string operations on nonstring
operands, the nonstring operands are first promoted to strings by
using their value as a string. When promoting null-valued operands
to strings, their value is always the empty string. For example,
the expression:
concat("The total is ", 2, " dollars and ", 57, " cents.")
evaluates
to "The total is 2 dollars and 57 cents."
Note: If during the evaluation of an expression an intermediate
step yields NaN, +Inf, or -Inf, FormCalc generates an error exception
and propagates that error for the remainder of the expression. As
such, the expression's value will always be 0. For example:
3 / 0 + 1
evaluates
to 0.
|
|
|