Formcalc Reference PDF
Formcalc Reference PDF
About FormCalc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Using FormCalc in Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Simple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Logical OR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Logical AND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Unary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Equality and inequality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Relational . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
If expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
While expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
For expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Foreach expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Break expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Continue expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Building blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Reference Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Property and method calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Built-in function calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Arithmetic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Abs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
i
Avg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Ceil . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Floor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Max . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Min . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Mod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Round . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Sum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Financial Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Apr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
CTerm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
FV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
IPmt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
NPV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Pmt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
PPmt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
PV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Logical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Choose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
HasValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Oneof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Within . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
ii
Miscellaneous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Eval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Null . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Ref . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
UnitType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
UnitValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
String Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
At . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Concat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Decode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Encode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Left . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Len . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Lower . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Ltrim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Parse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Replace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Right . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Rtrim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Str . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Stuff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Substr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Uuid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Upper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
WordNum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
iii
About FormCalc 1
1. About FormCalc
Designer provides users with FormCalc, a simple yet powerful calculation language for those with
little or no scripting experience.
The form developer can incorporate calculations and scripting to create a richer experience for the
recipient of the form. FormCalc facilitates fast and efficient form design without requiring a knowl-
edge of traditional scripting techniques or languages.
The built-in functions in FormCalc cover a wide range of areas including mathematics, dates and
times, strings, finance, logic, and the web. These areas represent the types of data that typically occur
in forms, and the functions provide quick and easy manipulation of the data in a useful way.
Within Designer, JavaScript™ is the default scripting language, with FormCalc as the alternative.
Scripting takes place on the various events that accompany each form object, and you can use a
mixture of JavaScript and FormCalc in interactive forms.
If you are using a server-based process, such as forms generator, to create forms for viewing in an
internet browser, FormCalc scripts on certain form object events do not render onto the HTML
form. This functionality is intended to prevent Internet browser errors from occurring when users
work with the completed form.
RELATED LINKS:
Alphabetical Functions List
1
Expressions
2. Expressions
Literals, operators, comments, keywords, identifiers, line terminators, and white space come
together to form a list of expressions, even if the list only contains a single expression. In general,
each expression in the list resolves to a value, and the value of the list as a whole is the value of the
last expression in the list.
For example, consider the following scenario of two fields on a form design:
Field2 10 * 3 + 5 * 4 50
The value of bothField1andField2after the evaluation of each field’s expression list is50.
FormCalc divides the various types of expressions that make up an expression list into the following
categories:
2.1. Simple
In 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:
2 - 3 * 10 / 2 + 7 2 - (3 * (10 / 2)) + 7 -6
2
Expressions 2
10 * 3 + 5 * 4 (10 * 3) + (5 * 4) 50
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
*,/
+,-
== , <> , eq , ne
& , and
Lowest | , or
In 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 promo-
tion occurs depends on the type of operand required by the operation.
When performing numeric operations involving non-numeric operands, the non-numeric oper-
ands are first promoted to their numeric equivalent. If the non-numeric operand does not success-
fully 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:
3
Expressions
(5 - "abc") * 3 (5 - 0) * 3 15
5 + null + 3 5 + 0 + 3 8
When 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 to20.
When 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 0.
4
Expressions 2
2.2. Assignment
An assignment expression sets the property identified by a given reference syntax to be the value of
a simple expression. For example:
$template.purchase_order.name.first = "Tony"
This sets the value of the form design object “first” toTony.
For more information on using syntax, see Referencing Objectsin Calculations and Scripts
2.3. Logical OR
A logical OR expression returns either true (1) if at least one of its operands is true (1), or false (0) if
both operands are false (0). If both operands are null, the expression returns null.
Logical OR |
or
Expression Returns
1 or 0 1(true)
0 | 0 0(false)
0 or 1 | 0 or 0 1(true)
A logical AND expression returns either true (1) if both operands are true (1), or false if at least one
of its operands is false (0). If both operands are null, the expression returns null.
5
Expressions
Expression Returns
1 and 0 0(false)
0 & 0 1(true)
2.5. Unary
A unary expression returns different results depending on which of the unary operators is used.
Unary - The arithmetic negation of the operand, or null if the operand is null.
NOTE: The arithmetic negation of a null operand yields the result null, whereas the logical negation of
a null operand yields the Boolean result true. This is justified by the common sense statement: If null
means nothing, then “not nothing” should be something.
These are examples of using the unary expression:
Expression Returns
-(17) -17
-(-17) 17
6
Expressions 2
Expression Returns
+(17) 17
+(-17) -17
not("true") 1 (true)
not(1) 0 (false)
Equality and inequality expressions return the result of an equality comparison of its operands.
Character
Expression representation Returns
Equality == eq True (1) when both operands compare identically, and false (0) if they
do not compare identically.
Inequality <> ne True (1) when both operands do not compare identically, and false (0) if
they compare identically.
The following special cases also apply when using equality operators:
• If either operand is null, a null comparison is performed. Null-valued operands compare iden-
tically whenever both operands are null, and compare differently whenever one operand is not
null.
• If both operands are references, both operands compare identically when they both refer to the
same object, and compare differently when they do not refer to the same object.
• If both operands are string valued, a locale-sensitive lexicographic string comparison is
performed on the operands. Otherwise, if they are not both null, the operands are promoted to
numeric values, and a numeric comparison is performed.
These are examples of using the equality and inequality expressions:
Expression Returns
3 == 3 1(true)
3 <> 4 1(true)
7
Expressions
Expression Returns
5 + 5 == 10 1(true)
2.7. Relational
A relational expression returns the Boolean result of a relational comparison of its operands.
Character
Expression representation Returns
Relational < lt True (1) when the first operand is less than the second operand, and
false (0) when the first operand is larger than the second operand.
> gt True (1) when the first operand is greater than the second operand, and
false (0) when the first operand is less than the second operand.
<= le True (1) when the first operand is less than or equal to the second
operand, and false (0) when the first operand is greater than the second
operand.
>= ge True (1) when the first operand is greater than or equal to the second
operand, and false (0) when the first operand is less than the second
operand.
The following special cases also apply when using relational operators:
• If either operand is null valued, a null comparison is performed. Null-valued operands
compare identically whenever both operands are null and the relational operator is
less-than-or-equal or greater than or equal, and compare differently otherwise.
• If both operands are string valued, a locale-sensitive lexicographic string comparison is
performed on the operands. Otherwise, if they are not both null, the operands are promoted to
numeric values, and a numeric comparison is performed.
These are examples of using the relational expression:
8
Expressions 2
Expression Returns
3 < 3 0(false)
3 > 4 0(false)
12 >= 12 1(true)
2.8. If expressions
An if expression is a conditional statement that evaluates a given simple expression for truth, and
then returns the result of a list of expressions that correspond to the truth value. If the initial simple
expression evaluates to false (0), FormCalc examines any elseif and else conditions for truth and
returns the results of their expression lists if appropriate.
If if ( simple expression ) The result of the list of expressions associated with any
then valid conditions stated in the if expression.
list of expressions You are not required to have any elseif(...) or else
elseif ( simple expression ) statements as part of your if expression, but you must
then state the end of the expression with endif.
list of expressions
else
list of expressions
endif
Expression Returns
9
Expressions
Expression Returns
if ( Field1 < Field2 ) then Varies with the values ofField1andField2. For example, if Field1 is
Field3 = 0 elseif ( Field1 20 and Field2 is 10, then this expression sets Field3 to 40.
> Field2 ) then Field3 =
40 elseif ( Field1 == Field2
) then Field3 = 10 endif
A while expression is an iterative statement or loop that evaluates a given simple expression. If the
result of the evaluation is true (1), FormCalc repeatedly examines the do condition and returns the
results of the expression lists. If the result is false (0), then control passes to the next statement.
A while expression is particularly well-suited to situations in which conditional repetition is needed.
Conversely, situations in which unconditional repetition is needed are often best dealt with using a
for expression.
Expressio
n Syntax Returns
While while ( simple expression The result of the list of expressions associated with the do
) do expression list condition.
endwhile
In the following example, the values of the elements are added to a drop-down list from an XML file
using the addItem method for all of the XML elements listed under list1 that are not equal to 3:
var List = ref(xfa.record.lists.list1)
var i = 0
while ( List.nodes.item(i+1).value ne "3")do
$.addItem (List.nodes.item(i).value,List.nodes.item(i+1).value)
i = i + 2
endwhile
10
Expressions 2
The value of the for expression is the value of the last evaluation list that was evaluated, or false (0).
The for condition initializes a FormCalc variable, which controls the looping action.
In the upto variant, the value of the loop variable will iterate from the start expression to the end
expression in step expression increments. If you omit the step expression, the step increment
defaults to 1.
In the downto variant, the value of the loop variable iterates from the start expression to the end
expression in step expression decrements. If the step expression is omitted, the step decrements
defaults to -1.
Iterations of the loop are controlled by the end expression value. Before each iteration, the end
expression is evaluated and compared to the loop variable. If the result is true (1), the expression list
is evaluated. After each evaluation, the step expression is evaluated and added to the loop variable.
Before each iteration, the end expression is evaluated and compared to the loop variable. In addition,
after each evaluation of the do condition, the step expression is evaluated and added to the loop vari-
able.
A for loop terminates when the start expression has surpassed the end expression. The start expres-
sion can surpass the end expression in either an upwards direction, if you use upto, or in a downward
direction, if you use downto.
Expressio
n Syntax Returns
For for variable = start expression The result of the list of expressions
(upto | downto ) end expression associated with the do condition.
(step step expression ) do
expression list
endfor
The start, end, and step expressions must all be simple
expressions.
In the following example, the values of the elements are added to a drop-down list from an XML file
using the addItem method for all of the XML elements listed under list1:
var List = ref(xfa.record.lists.list1)
for i=0 upto List.nodes.length - 1 step 2 do
$.addItem (List.nodes.item(i).value,"")
endfor
A foreach expression iterates over the expression list for each value in its argument list.
11
Expressions
The value of the foreach expression is the value of the last expression list that was evaluated, or zero
(0), if the loop was never entered.
The in condition, which is executed only once (after the loop variable has been declared) controls
the iteration of the loop. Before each iteration, the loop variable is assigned successive values from
the argument list. The argument list cannot be empty.
Expressio
n Syntax Returns
Foreach foreach variable in( argument list The value of the last expression list that was
)do evaluated, or zero(0), if the loop was never
expression list entered.
endfor
Use a comma (,) to separate more
than one simple expression in the
argument list.
In the following example, only the values of the “display” XML elements are added to the foreach
drop-down list.
foreach Item in (xfa.record.lists.list1.display[*]) do
$.addItem(Item,"")
endfor
A break expression causes an immediate exit from the innermost enclosing while, for, or foreach
expression loop. Control passes to the expression following the terminated loop.
The value of the break expression is always the value zero (0).
Break break Passes control to the expression following the terminated loop.
In the following example, an if condition is placed in the while loop to check whether the current
value is equal to “Display data for 2”. If true, the break executes and stops the loop from continuing.
var List = ref(xfa.record.lists.list1)
var i=0
while (List.nodes.item(i+1).value ne "3") do
$.addItem(List.nodes.item(i).value,List.nodes.item(i+1).value)
i = i + 2
if (List.nodes.item(i) eq "Display data for 2" then
break
12
Expressions 2
endif
endwhile
A continue expression causes the next iteration of the innermost enclosing while, for, or foreach
loop.
The value of the continue expression is always the value zero (0).
Expressio
n Syntax Returns
Continue continu When used in a while expression, control is passed to the while condition. When used
e in a for expression, control is passed to the step expression.
The object of the following example is to populate the drop-down list with values from the XML file.
If the value of the current XML element is “Display data for 3,” then the while loop exits via the break
expression. If the value of the current XML element is “Display data for 2”, then the script adds 2 to
the variablei(which is the counter) and immediately the loop moves on to its next cycle. The last two
lines are ignored when the value of the current XML element is “Display data for 2”.
var List = ref(xfa.record.lists.list1)
var i = 0
while (List.nodes.item(i+1).value ne "5") do
if (List.nodes.item(i) eq "Display data for 3") then
break
endif
if (List.nodes.item(i) eq "Display data for 2" then
i=i+2
continue
endif
$.addItem(List.nodes.item(i).value,List.nodes.item(i+1).value)
i=i+2
endwhile
The FormCalc language consists of building blocks that make up FormCalc expressions. Each Form-
Calc expression is a sequence of some combination of these building blocks.
13
Expressions
2.14.1. Literals
Literals are constant values that form the basis of all values that pass to FormCalc for processing. The
two general types of literals are numbers and strings.
Number literals
A number literal is a sequence of mostly digits consisting of one or more of the following characters:
an integer, a decimal point, a fractional segment, an exponent indicator (“e” or “E”), and an option-
ally signed exponent value. These are all examples of literal numbers:
• -12
• 1.5362
• 0.875
• 5.56e-2
• 1.234E10
It is possible to omit either the integer or fractional segment of a literal number, but not both. In
addition, within the fractional segment, you can omit either the decimal point or the exponent value,
but not both.
All number literals are internally converted to Institute of Electrical and Electronics Engineers
(IEEE) 64-bit binary values. However, IEEE values can only represent a finite quantity of numbers,
so certain values do not have a representation as a binary fraction. This is similar to the fact that
certain values, such as 1/3, do not have a precise representation as a decimal fraction (the decimal
value would need an infinite number of decimal places to be entirely accurate).
The values that do not have a binary fraction equivalent are generally number literals with more than
16 significant digits prior to their exponent. FormCalc rounds these values to the nearest represent-
able IEEE 64-bit value in accordance with the IEEE standard. For example, the value:
123456789.012345678
This behavior can sometimes lead to surprising results. FormCalc provides a function, Round, which
returns a given number rounded to a given number of decimal places. When the given number is
exactly halfway between two representable numbers, it is rounded away from zero. That is, the
number is rounded up if positive and down if negative. In the following example:
14
Expressions 2
Round(0.124, 2)
returns0.12,
and
Round(.125, 2)
returns0.13.
Given this convention, one might expect that:
Round(0.045, 2)
returns0.05.
However, the IEEE 754 standard dictates that the number literal0.045be approximated
to0.0449999999999999. This approximation is closer to0.04than to0.05. Therefore,
Round(0.045, 2)
returns0.04.
This also conforms to the IEEE 754 standard.
IEEE 64-bit values support representations like NaN (not a number), +Inf (positive infinity), and
-Inf (negative infinity). FormCalc does not support these, and expressions that evaluate to NaN,
+Inf, or -Inf result in an error exception, which passes to the remainder of the expression.
String literals
A string literal is a sequence of any Unicode characters within a set of quotation marks. For example:
"The cat jumped over the fence."
"Number 15, Main street, California, U.S.A"
The string literal""defines an empty sequence of text characters called the empty string.
To embed a quotation mark (") character within a literal string, you must insert two quotation
marks. For example:
"The message reads: ""Warning: Insufficient Memory"""
All Unicode characters have an equivalent 6 character escape sequence consisting of\ufollowed by
four hexadecimal digits. Within any literal string, it is possible to express any character, including
control characters, using their equivalent Unicode escape sequence. For example:
"\u0047\u006f\u0066\u0069\u0073\u0068\u0021"
"\u000d" (carriage return)
"\u000a" (newline character)
15
Expressions
2.14.2. Operators
Addition +
Division /
Equality == eq
<> ne
Logical OR | or
Multiplication *
Subtraction -
Unary -
+
not
2.14.3. Comments
Comments are sections of code that FormCalc does not execute. Typically comments contain infor-
mation or instructions that explain the use of a particular fragment of code. FormCalc ignores all
information stored in comments at run time.
You can specify a comment by using either a semi-colon (;) or a pair of slashes (//). In FormCalc, a
comment extends from its beginning to the next line terminator.
16
Expressions 2
Comment ;
//
For example:
// This is a type of comment
First_Name="Tony"
Initial="C" ;This is another type of comment
Last_Name="Blue"
Commenting all of the FormCalc calculations for a particular event generates an error when you
preview your form in the Preview PDF tab or when you view the final PDF. Each FormCalc calcula-
tion is required to return a value, and FormCalc does not consider comments to be values.
To prevent the commented FormCalc code from returning an error, you must do one of the
following actions:
• Remove the commented code from the event
• Add an expression that returns a value to the FormCalc code on the event
To prevent the value of the expression from producing unwanted results on your form, use one of
the following types of expressions:
• A simple expression consisting of a single character, as shown in the following example:
// First_Name="Tony"
// Initial="C"
// Last_Name="Blue"
//
// The simple expression below sets the value of the event to zero.
0
• An assignment expression that retains the value of the object. Use this type of expression if
your commented FormCalc code is located on the calculate event to prevent the actual value
of the object from being altered, as shown in the following example:
// First_Name="Tony"
// Initial="C"
// Last_Name="Blue"
//
// The assignment expression below sets the value of the current
// field equal to itself.
$.rawValue = $.rawValue
17
Expressions
2.14.4. Keywords
Keywords in FormCalc are reserved words and are case-insensitive. Keywords are used as parts of
expressions, special number literals, and operators.
The following table lists the FormCalc keywords. Do not use any of these words when naming
objects on your form design.
continue eq le this
do exit lt throw
end ge null
endfor gt or
endfunc if return
2.14.5. Identifiers
18
Expressions 2
Identifier A..Z,a..z
$
!
_
Line terminators are used for separating lines and improving readability.
The following table lists the valid FormCalc line terminators:
White space characters separate various objects and mathematical operations from each other.
These characters are strictly for improving readability and are irrelevant during FormCalc
processing.
Space #x20
19
Expressions
2.15. Variables
Within your calculations, FormCalc allows you to create and manipulate variables for storing data.
The name you assign to each variable you create must be a unique Identifiers.
For example, the following FormCalc expressions define the userName variable and set the value of
a text field to be the value of userName.
var userName = "Tony Blue"
TextField1.rawValue = userName
You can reference variables that you define in the Variables tab of the Form Properties dialog box in
the same way. The following FormCalc expression uses the Concat function to set the value of the
text field using the form variables salutation and name.
TextField1.rawValue = Concat(salutation, name)
NOTE: A variable you create using FormCalc will supersede a similarly named variable you define in
the Variables tab of the Form Properties dialog box.
FormCalc provides access to form design object properties and values using a reference syntax. The
following example demonstrates both assigning and retrieving object values:
Invoice_Total.rawValue = Invoice_SubTotal.rawValue * (8 / 100)
In this case the reference syntax Invoice_Total assigns the value of Invoice_SubTotal *
(8 / 100) to the field Invoice_Total.
In the context of form design, a fully qualified reference syntax enables access to all the objects on a
form design.
To make accessing object properties and values easier, FormCalc includes reference syntax shortcuts
to reduce the effort required to create references.
20
Expressions 2
Notation
Example
$ = "Tony Blue"
The above example sets the value of the current field or object to Tony Blue.
Notation
$data
Example
$data.purchaseOrder.total
is equivalent to
xfa.datasets.data.purchaseOrder.total
Notation
$event
Example
$event.name
is equivalent to
xfa.event.name
21
Expressions
Notation
$form
Example
$form.purchaseOrder.tax
is equivalent to stating
xfa.form.purchaseOrder.tax
Notation
$host
Example
$host.messageBox("Hello world")
is equivalent to
xfa.host.messageBox("Hello world")
Notation
$layout
22
Expressions 2
Example
$layout.ready
is equivalent to stating
xfa.layout.ready
Represents the current record of a collection of data, such as from an XML file.
Notation
$record
Example
$record.header.txtOrderedByCity
references the txtOrderedByCity node within the header node of the current XML data.
Notation
$template
Example
$template.purchaseOrder.item
is equivalent to
xfa.template.purchaseOrder.item
23
Expressions
Notation
Example
!data
is equivalent to
xfa.datasets.data
Selects all form objects within a given container, such as a subform, regardless of name, or selects all
objects that have a similar name.
You can use the ‘*’ (asterisk) syntax with JavaScript if it used with the resolveNode method.
Notation
Example
For example, the following expression selects all objects named item on a form:
xfa.form.form1.item[*]
You can use two dots at any point in your reference syntax to search for objects that are a part of any
subcontainer of the current container object, such as a subform.
You can use the ‘..’ (double period) syntax with JavaScript if it used with the resolveNode
method.
Notation
..
24
Expressions 2
Example
is equivalent to
Subform_Page.Subform1[0].Subform3.TextField2[0]
The number sign (#) notation is used to denote one of the following items in a reference syntax:
• An unnamed object
• Specify a property in a reference syntax if a property and an object have the same name
You can use the ‘#’ (number sign) syntax with JavaScript if it used with the resolveNode method.
Notation
Example
The following reference syntax accesses the name property of a subform if the subform also contains
a field named name:
xfa.form.form1.#subform.#name
25
Expressions
Notation
[ ]
Example
To construct an occurrence value reference, place square brackets ([ ]) after an object name, and
enclose within the brackets one of the following values:
• [ n ], wherenis an absolute occurrence index number beginning at 0. An occurrence number
that is out of range does not return a value. For example,
xfa.form.form1.#subform.Quantity[3]
refers to the fourth occurrence of the Quantity object.
• [ +/- n ], where n indicates an occurrence relative to the occurrence of the object making
the reference. Positive values yield higher occurrence numbers, and negative values yield lower
occurrence numbers. For example,
xfa.form.form1.#subform.Quantity[+2]
This reference yields the occurrence of Quantity whose occurrence number is two more than
the occurrence number of the container making the reference. For example, if this reference
was attached to the Quantity[2]object , the reference would be the same as
xfa.template.Quantity[4]
If the computed index number is out of range, the reference returns an error.
The most common use of this syntax is for locating the previous or next occurrence of a partic-
ular object. For example, every occurrence of the Quantity object (except the first) might use
Quantity[-1] to get the value of the previous Quantity object.
• [*]indicates multiple occurrences of an object. The first named object is found, and objects
of the same name that are siblings to the first are returned. Note that using this notation returns
a collection of objects. For example,
xfa.form.form1.#subform.Quantity[*]
• This expression refers to all objects with a name ofQuantitythat are siblings to the first
occurrence ofQuantityfound by the reference.
26
Expressions 2
Using the tree for reference, these expressions return the following objects:
• Subform_Page.Subform1[*]returns bothSubform1objects.
• Subform_Page.Subform1.Subform3.TextField2[*]returns
twoTextField2objects.Subform_Page.Subform1resolves to the
firstSubform1object on the left, andTextField2[*]evaluates relative to
theSubform3object.
• Subform_Page.Subform1[*].TextField1returns both of
theTextField1instances.Subform_Page.Subform1[*]resolves to
bothSubform1objects, andTextField1evaluates relative to theSubform1objects.
• Subform_Page.Subform1[*].Subform3.TextField2[1]returns the second and
fourthTextField2objects from the left.Subform_Page.Subform1[*]resolves to
bothSubform1objects, andTextField2[1]evaluates relative to theSubform3objects.
• Subform_Page.Subform1[*].Subform3[*]returns both instances of
theSubform3object.
• Subform_Page.*returns bothSubform1objects and theSubform2object.
• Subform_Page.Subform2.*returns the two instances of theNumericField2object.
• You can use the ‘ [ ]’ (square bracket) syntax with JavaScript if it used with the
resolveNode method.
Designer defines a variety of properties and methods for all objects on a form design. FormCalc
provides access to these properties and methods and allows you to use them to modify the appear-
ance and behavior of objects on your form. Similar to a function call, you invoke properties and
methods by passing arguments to them in a specific order. The number and type of arguments in
each property and method are specific to each object type.
NOTE: Different form design objects support different properties and methods. For a complete list of the
properties and methods objects support, see Aboutthe Scripting Reference.
27
Expressions
FormCalc supports a large set of built-in functions with a wide range of capabilities. The names of
the functions are case-insensitive, but unlike keywords, FormCalc does not reserve the names of the
functions. This means that calculations on forms with objects whose names coincide with the names
of FormCalc functions do not conflict.
Functions may or may not require some set of arguments to execute and return a value. Many func-
tions have arguments that are optional, meaning it is up to you to decide if the argument is necessary
for the particular situation.
FormCalc evaluates all function arguments in order, beginning with the lead argument. If an attempt
is made to pass less than the required number of arguments to a function, the function generates an
error exception.
Each function expects each argument in a particular format, either as a number literal or string
literal. If the value of an argument does not match what a function expects, FormCalc converts the
value. For example:
Len(35)
The Len function actually expects a literal string. In this case, FormCalc converts the argument from
the number 35 to the string “35”, and the function evaluates to 2.
However, in the case of a string literal to number literal, the conversion is not so simple. For example:
Abs("abc")
The Abs function expects a number literal. FormCalc converts the value of all string literals as 0. This
can cause problems in functions where a 0 value forces an error, such as in the case of the Apr func-
tion.
Some function arguments only require integral values; in such cases, the passed arguments are
always promoted to integers by truncating the fractional part.
Here is a summary of the key properties of built-in functions:
• Built-in function names are case-insensitive.
• The built-in functions are predefined, but their names are not reserved words. This means that
the built-in function Max never conflicts with an object, object property, or object method
named Max.
• Many of the built-in functions have a mandatory number of arguments, which can be followed
by a optional number of arguments.
• A few built-in functions, Avg, Count, Max, Min, Sum, and Concat, accept an indefinite
number of arguments.
For a complete listing of all the FormCalc functions, see the Alphabetical FunctionsList.
28
Alphabetical Functions List 3
Avg Evaluates a set of number values and/or expressions and returns the Arithmetic
average of the non-null elements contained within that set.
Ceil Returns the whole number greater than or equal to a given number. Arithmetic
Count Evaluates a set of values and/or expressions and returns the number Arithmetic
of non-null elements contained within the set.
CTerm Returns the number of periods needed for an investment earning a Financial
fixed, but compounded, interest rate to grow to a future value.
Date Returns the current system date as the number of days since the Date and Time
Epoch
Date2Num Returns the number of days since the Epoch, given a date string. Date and Time
DateFmt Returns a date format string, given a date format style. Date and Time
Floor Returns the largest whole number that is less than or equal to the Arithmetic
given value.
29
Alphabetical Functions List
Format Formats the given data according to the specified picture format String
string.
IPmt Returns the amount of interest paid on a loan over a set period of Financial
time.
IsoDate2Num Returns the number of days since the Epoch, given an valid date Date and Time
string.
IsoTime2Num Returns the number of milliseconds since the Epoch, given a valid Date and Time
time string.
Left Extracts a specified number of characters from a string, starting with String
the first character on the left.
LocalDateFmt Returns a localized date format string, given a date format style. Date and Time
LocalTimeFmt Returns a localized time format string, given a time format style. Date and Time
Ltrim Returns a string with all leading white space characters removed. String
Max Returns the maximum value of the non-null elements in the given Arithmetic
set of numbers.
Min Returns the minimum value of the non-null elements of the given set Arithmetic
of numbers.
NPV Returns the net present value of an investment based on a discount Financial
rate and a series of periodic future cash flows.
Null Returns the null value. The null value means no value. Miscellaneous
Num2Date Returns a date string, given a number of days since the Epoch. Date and Time
30
Alphabetical Functions List 3
Num2GMTime Returns a GMT time string, given a number of milliseconds from the Date and Time
Epoch.
Num2Time Returns a time string, given a number of milliseconds from the Date and Time
Epoch.
Oneof Returns true (1) if a value is in a given set, and false (0) if it is not. Logical
Parse Analyzes the given data according to the given picture format. String
Pmt Returns the payment for a loan based on constant payments and a Financial
constant interest rate.
PPmt Returns the amount of principal paid on a loan over a period of time. Financial
Rate Returns the compound interest rate per period required for an Financial
investment to grow from present to future value in a given period.
Replace Replaces all occurrences of one string with another within a specified String
string.
Right Extracts a number of characters from a given string, beginning with String
the last character on the right.
Round Evaluates a given numeric value or expression and returns a number Arithmetic
rounded to the given number of decimal places.
Rtrim Returns a string with all trailing white space characters removed. String
Str Converts a number to a character string. FormCalc formats the result String
to the specified width and rounds to the specified number of decimal
places.
Sum Returns the sum of the non-null elements of a given set of numbers. Arithmetic
31
Alphabetical Functions List
Term Returns the number of periods needed to reach a given future value Financial
from periodic constant payments into an interest-bearing account.
Time Returns the current system time as the number of milliseconds since Date and Time
the Epoch.
Time2Num Returns the number of milliseconds since the Epoch, given a time Date and Time
string.
TimeFmt Returns a time format, given a time format style. Date and Time
UnitValue Returns the numeric value of a measurement with its associated Miscellaneous
unitspan, after an optional unit conversion.
Within Returns true (1) if the test value is within a given range, and false (0) Logical
if it is not.
32
Arithmetic Functions 4
4. Arithmetic Functions
Arithmetic functions perform a range of mathematical operations.
4.1. Abs
Returns the absolute value of a numeric value or expression, or returns null if the value or expression
is null.
4.1.1. Syntax
Abs(n1)
4.1.2. Parameters
Parameter Description
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
4.1.3. Examples
Expression Returns
Abs(1.03) 1.03
Abs(-1.03) 1.03
Abs(0) 0
33
Arithmetic Functions
4.2. Avg
Evaluates a set of number values and/or expressions and returns the average of the non-null
elements contained within that set.
4.2.1. Syntax
Avg(n1 [, n2 ...])
4.2.2. Parameters
Parameter Description
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
4.2.3. Examples
Expression Returns
Avg(Price[0], Price[1], Price[2], The average value of the first four non-null occurrences
Price[3]) ofPrice.
34
Arithmetic Functions 4
4.3. Ceil
Returns the whole number greater than or equal to a given number, or returns null if its parameter
is null.
4.3.1. Syntax
Ceil(n)
4.3.2. Parameters
Parameter Description
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
4.3.3. Examples
Expression Returns
Ceil(2.5875) 3
Ceil(-5.9) -5
Ceil("abc") 0
4.4. Count
Evaluates a set of values and/or expressions and returns the count of non-null elements contained
within the given set.
35
Arithmetic Functions
4.4.1. Syntax
Count(n1 [, n2 ...])
4.4.2. Parameters
Parameter Description
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
4.4.3. Examples
Expression Returns
4.5. Floor
Returns the largest whole number that is less than or equal to the given value.
4.5.1. Syntax
Floor(n)
36
Arithmetic Functions 4
4.5.2. Parameters
Parameter Description
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
4.5.3. Examples
Expression Returns
Floor(21.3409873) 21
Floor(5.999965342) 5
Floor(3.2 * 15) 48
4.6. Max
Returns the maximum value of the non-null elements in the given set of numbers.
4.6.1. Syntax
Max(n1 [, n2 ...])
4.6.2. Parameters
Parameter Description
37
Arithmetic Functions
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
4.6.3. Examples
Expression Returns
Max("abc") 0
4.7. Min
Returns the minimum value of the non-null elements of the given set of numbers.
4.7.1. Syntax
Min(n1 [, n2 ...])
4.7.2. Parameters
Parameter Description
38
Arithmetic Functions 4
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
4.7.3. Examples
Expression Returns
Min("abc") 0
4.8. Mod
Returns the modulus of one number divided by another. The modulus is the remainder of the divi-
sion of the dividend by the divisor. The sign of the remainder always equals the sign of the dividend.
4.8.1. Syntax
Mod(n1, n2)
4.8.2. Parameters
Parameter Description
39
Arithmetic Functions
Parameter Description
4.8.3. Examples
Expression Returns
Mod(64, -3) 1
Mod(-13,3) -1
Mod("abc", 2) 0
Mod(X[0], Y[9]) The first occurrence ofXis used as the dividend and the tenth
occurrence ofYis used as the divisor.
Mod(Round(Value[4], 2), The first fifth occurrence ofValuerounded to two decimal places
Max(Value[*])) is used as the dividend and the highest of all non-null occurrences
ofValueis used as the divisor.
See also Max and Round.
4.9. Round
Evaluates a given numeric value or expression and returns a number rounded to a given number of
decimal places.
4.9.1. Syntax
Round(n1 [, n2])
40
Arithmetic Functions 4
4.9.2. Parameters
Parameter Description
n2(optional) The number of decimal places with which to evaluaten1to a maximum of 12.
If you do not include a value forn2, or ifn2is invalid, the function assumes the number of
decimal places is 0.
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
4.9.3. Examples
Expression Returns
Round(12.389764537, 4) 12.3898
Round(20/3, 2) 6.67
Round(8.9897, "abc") 9
Round(FV(400, 0.10/12, 904195.17. This takes the value evaluated using theFVfunction and
30*12), 2) rounds it to two decimal places.
See also FV.
4.10. Sum
4.10.1. Syntax
Sum(n1 [, n2 ...])
41
Arithmetic Functions
4.10.2. Parameters
Parameter Description
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
4.10.3. Examples
Expression Returns
Sum(2, 4, 6, 8) 20
Sum(-2, 4, -6, 8) 4
Sum(Round(20/3, 2), Max(Amount[*]), Totals the value of 20/3 rounded to two decimal
Min(Amount[*])) places, as well as the largest and smallest non-null
occurrences ofAmount.
See also Max, Min, and Round.
42
Date and Time Functions 5
5.1.1. Epoch
Date values and time values have an associated origin or epoch, which is a moment in time from
which time begins. Any date value and any time value prior to its epoch is invalid.
The unit of value for all date functions is the number of days since the epoch. The unit of value for
all time functions is the number of milliseconds since the epoch.
Designer defines day one for the epoch for all date functions as Jan 1, 1900, and millisecond one for
the epoch for all time functions is midnight, 00:00:00, Greenwich Mean Time (GMT). This defini-
tion means that negative time values can be returned to users in time zones east of GMT.
A date format is a shorthand specification of how a date appears. It consists of various punctuation
marks and symbols that represent the formatting that the date must use. The following table lists
examples of date formats.
MM/DD/YY 11/11/78
DD/MM/YY 25/07/85
The format of dates is governed by an ISO standard. Each country or region specifies its own date
formats. The four general categories of date formats are short, medium, long, and full. The following
table contains examples of different date formats from different locales for each of the categories.
43
Date and Time Functions
fr_FR EEEE, ' le ' D MMMM YYYY (Full) Lundi, le 29 Octobre, 1990
French (France)
A time format is a shorthand specification to format a time. It consists of punctuations, literals, and
pattern symbols. The following table lists examples of time formats.
h:MM A 7:15 PM
HH:MM:SS 21:35:26
Time formats are governed by an ISO standard. Each nation specifies the form of its default, short,
medium, long, and full-time formats. The locale identifies the format of times that conform to the
standards of that nation.
The following table contains some examples of different date formats from different locales for each
of the categories.
44
Date and Time Functions 5
The following symbols must be used to create date and time patterns for date/time fields. Certain
date symbols are only used in Chinese, Japanese, and Korean locales. These symbols are also speci-
fied below.
NOTE: The comma (,), dash (-), colon (:), slash (/), period (.), and space ( ) are treated as literal values
and can be included anywhere in a pattern. To include a phrase in a pattern, delimit the text string
with single quotation marks ('). For example, 'Your payment is due no later than'
MM-DD-YYcan be specified as the display pattern.
E One-digit (1-7) day of the week, where 3 (because January 1, 2008 is a Tuesday)
(1=Sunday)
45
Date and Time Functions
Several additional date patterns are available for specifying date patterns in Chinese, Japanese, and
Korean locales.
Japanese eras can be represented by several different symbols. The final four era symbols provide
alternative symbols to represent Japanese eras.
CJK date
symbol Description
DDDD The locale’s tens rule ideographic numeric valued day of the month
g The locale’s alternate era name. For the current Japanese era, Heisei, this pattern displays the
ASCII letter H (U+48)
gg The locale’s alternate era name. For the current Japanese era, this pattern displays the ideograph
that is represented by the Unicode symbol (U+5E73)
ggg The locale’s alternate era name. For the current Japanese era, this pattern displays the ideographs
that are represented by the Unicode symbols (U+5E73 U+6210)
g The locale’s alternate era name. For the current Japanese era, this pattern displays the full width
letter H (U+FF28)
46
Date and Time Functions 5
CJK date
symbol Description
g g The locale’s alternate era name. For the current Japanese era, this pattern displays the ideograph
that is represented by the Unicode symbol (U+337B)
Formatted value
Time Locale-sensitive input for English
symbol Description value (USA) locale
47
Date and Time Functions
Formatted value
Time Locale-sensitive input for English
symbol Description value (USA) locale
Reserved symbols
The following symbols have special meanings and cannot be used as literal text.
Symbo
l Description
? When submitted, the symbol matches any one character. When merged for display, it
becomes a space.
* When submitted, the symbol matches 0 or Unicode white space characters. When merged
for display, it becomes a space.
+ When submitted, the symbol matches one or more Unicode white space characters. When
merged for display, it becomes a space.
5.1.5. Locales
For a list of supported languages, see Locales topic in the Using Designer guide.
5.2. Date
Returns the current system date as the number of days since the epoch.
48
Date and Time Functions 5
5.2.1. Syntax
Date()
5.2.2. Parameters
None
5.2.3. Examples
Expression Returns
Date() 37875(the number of days from the epoch to September 12, 2003)
5.3. Date2Num
Returns the number of days since the epoch, given a date string.
5.3.1. Syntax
Date2Num(d [, f [, k ]])
5.3.2. Parameters
Parameter Description
d A date string in the format supplied byfthat also conforms to the locale given byk.
f(optional) A date format string. Iffis omitted, the default date formatMMM D, YYYYis used.
k(optional) A locale identifier string that conforms to the locale naming standards. Ifkis omitted (or is invalid),
the ambient locale is used.
The function returns a value of0 if any of the following conditions are true:
• The format of the given date does not match the format specified in the function.
49
Date and Time Functions
5.3.3. Examples
Expression Returns
Date2Num("1/1/1900", "D/M/YYYY") 1
5.4. DateFmt
5.4.1. Syntax
DateFmt([n [, k ]])
50
Date and Time Functions 5
5.4.2. Parameters
Parameter Description
k(optional) A locale identifier string that conforms to the locale naming standards. Ifkis omitted (or is invalid),
the ambient locale is used.
5.4.3. Examples
Expression Returns
5.5. IsoDate2Num
Returns the number of days since the epoch began, given a valid date string.
5.5.1. Syntax
IsoDate2Num(d)
51
Date and Time Functions
5.5.2. Parameters
Parameter Description
5.5.3. Examples
Expression Returns
IsoDate2Num("1900") 1
IsoDate2Num("1900-01") 1
IsoDate2Num("1900-01-01") 1
IsoDate2Num("19960315T20:20:20") 35138
IsoDate2Num("2000-03-01") - IsoDate2Num("20000201") 29
5.6. IsoTime2Num
Returns the number of milliseconds since the epoch, given a valid time string.
5.6.1. Syntax
IsoTime2Num(d)
5.6.2. Parameters
Parameter Description
52
Date and Time Functions 5
5.6.3. Examples
Expression Returns
IsoTime2Num("19111111T131313+01") 43993001, for a user located in the Eastern Time (ET) zone.
5.7. LocalDateFmt
5.7.1. Syntax
LocalDateFmt([n [, k ]])
5.7.2. Parameters
Parameter Description
k(optional) A locale identifier string that conforms to the locale naming standards. Ifkis omitted (or is
invalid), the ambient locale is used.
53
Date and Time Functions
5.7.3. Examples
Expression Returns
5.8. LocalTimeFmt
5.8.1. Syntax
LocalTimeFmt([n [, k ]])
5.8.2. Parameters
Parameter Description
k(Optional) A locale identifier string that conforms to the locale naming standards. Ifkis omitted (or is invalid),
the ambient locale is used.
54
Date and Time Functions 5
5.8.3. Examples
Expression Returns
5.9. Num2Date
5.9.1. Syntax
5.9.2. Parameters
Parameter Description
f(Optional) A date format string. If you do not include a value forf, the function uses the default date format
MMM D, YYYY.
k(Optional) A locale identifier string that conforms to the locale naming standards. If you do not include a
value for k, or if k is invalid, the function uses the ambient locale.
The function returns a value of 0 if any of the following conditions are true:
• The format of the given date does not match the format specified in the function.
55
Date and Time Functions
5.9.3. Examples
Expression Returns
5.10. Num2GMTime
Returns a GMT time string, given a number of milliseconds from the epoch.
5.10.1. Syntax
5.10.2. Parameters
Parameter Description
f(Optional) A time format string. If you do not include a value for f, the function uses the default time
formatH:MM:SS A.
k(Optional) A locale identifier string that conforms to the locale naming standards. If you do not include a value
fork, or if kis invalid, the function uses the ambient locale.
56
Date and Time Functions 5
The function returns a value of 0 if any of the following conditions are true:
• The format of the given time does not match the format specified in the function.
• Either the locale or time format supplied in the function is invalid.
Insufficient information is provided to determine a unique time since the epoch (that is, any
information regarding the time is missing or incomplete.
5.10.3. Examples
Expression Returns
5.11. Num2Time
5.11.1. Syntax
5.11.2. Parameters
Parameter Description
f(Optional) A time format string. If you do not include a value forf, the function uses the default time
formatH:MM:SS A.
57
Date and Time Functions
Parameter Description
k(Optional) A locale identifier string that conforms to the locale naming standards. If you do not include a value
fork, or ifkis invalid, the function uses the ambient locale.
The function returns a value of 0 if any of the following conditions are true:
• The format of the given time does not match the format specified in the function.
• Either the locale or time format supplied in the function is invalid.
Insufficient information is provided to determine a unique time since the epoch (that is, any
information regarding the time is missing or incomplete.
5.11.3. Examples
Expression Returns
5.12. Time
Returns the current system time as the number of milliseconds since the epoch.
5.12.1. Syntax
Time()
58
Date and Time Functions 5
5.12.2. Parameters
None
5.12.3. Examples
Expression Returns
Time() 71533235at precisely 3:52:15 P.M. on September 15th, 2003 to a user in the Eastern Standard
Time (EST) zone.
5.13. Time2Num
Returns the number of milliseconds since the epoch, given a time string.
5.13.1. Syntax
Time2Num(d [, f [, k ]])
5.13.2. Parameters
Parameter Description
d A time string in the format supplied by f that also conforms to the locale given by k.
f(Optional) A time format string. If you do not include a value forf, the function uses the default time
formatH:MM:SS A.
k(Optional) A locale identifier string that conforms to the locale naming standards. If you do not include a
value fork, or if kis invalid, the function uses the ambient locale.
The function returns a value of 0 if any of the following conditions are true:
• The format of the given time does not match the format specified in the function.
59
Date and Time Functions
5.13.3. Examples
Expression Returns
5.14. TimeFmt
5.14.1. Syntax
TimeFmt([n [, k ]])
60
Date and Time Functions 5
5.14.2. Parameters
Parameter Description
k(Optional) A locale identifier string that conforms to the locale naming standards. Ifkis omitted (or is invalid),
the ambient locale is used.
5.14.3. Examples
Expression Returns
61
Financial Functions
6. Financial Functions
Financial functions perform a variety of interest, principal, and evaluation calculations related to the
financial sector.
6.1. Apr
6.1.1. Syntax
6.1.2. Parameters
Parameter Description
n3 A numeric value or expression representing the number of periods in the loan’s duration.
If any parameter is null, the function returns null. If any parameter is negative or 0, the function
returns an error.
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
6.1.3. Examples
The following expressions are examples that use the Apr function:
62
Financial Functions 6
Expression Returns
Apr(P_Value, Payment, Time) This example uses variables in place of actual numeric values or
expressions.
6.2. CTerm
Returns the number of periods needed for an investment earning a fixed, but compounded, interest
rate to grow to a future value.
NOTE: Interest rate calculation methods differ from country to country. This function calculates an
interest rate based on U.S. interest rate standards.
6.2.1. Syntax
6.2.2. Parameters
Parameter Description
If any parameter is null, the function returns null. If any parameter is negative or 0, the function
returns an error.
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
63
Financial Functions
6.2.3. Examples
The following expressions are examples that use the CTerm function:
Expression Returns
6.3. FV
Returns the future value of consistent payment amounts made at regular intervals at a constant
interest rate.
NOTE: Interest rate calculation methods differ from country to country. This function calculates an
interest rate based on U.S. interest rate standards.
6.3.1. Syntax
6.3.2. Parameters
Parameter Description
n2 A numeric value or expression representing the interest per period of the investment.
The function returns an error if either of the following conditions are true:
• Either of n1 or n3 are negative or 0.
64
Financial Functions 6
• n2 is negative.
If any of the parameters are null, the function returns null.
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point
numeric values. For more information, see Numberliterals.
6.3.3. Examples
Expression Returns
FV(400, 0.10 / 12, 30 * 904195.16991842445. This is the value, after 30 years, of a $400 a
12) month investment growing at 10% annually.
FV(Payment[0], Int_Rate / This example uses variables in place of actual numeric values or
4, Time) expressions.
6.4. IPmt
Returns the amount of interest paid on a loan over a set period of time.
NOTE: Interest rate calculation methods differ from country to country. This function calculates an
interest rate based on U.S. interest rate standards.
6.4.1. Syntax
6.4.2. Parameters
Parameter Description
n2 A numeric value or expression representing the annual interest rate of the investment.
65
Financial Functions
Parameter Description
n4 A numeric value or expression representing the first month in which a payment will be made.
n5 A numeric value or expression representing the number of months for which to calculate.
The function returns an error if either of the following conditions are true:
• n1, n2, or n3 are negative or 0.
• Either n4 or n5 are negative.
If any parameter is null, the function returns null. If the payment amount (n3) is less than the
monthly interest load, the function returns0.
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point
numeric values. For more information, see Numberliterals.
6.4.3. Examples
The following expressions are examples that use the IPmt function:
Expression Returns
IPmt(160000, 0.0475, 980, 7103.80833569485.The amount of interest repaid during the third
24, 12) year of the loan.
IPmt(15000, 0.065, 65.50, 0, because the monthly payment is less than the interest the loan accrues
15, 1) during the month.
6.5. NPV
Returns the net present value of an investment based on a discount rate and a series of periodic
future cash flows.
NOTE: Interest rate calculation methods differ from country to country. This function calculates an
interest rate based on U.S. interest rate standards.
66
Financial Functions 6
6.5.1. Syntax
NPV(n1, n2 [, ...])
6.5.2. Parameters
Parameter Description
n1 A numeric value or expression representing the discount rate over a single period.
n2 A numeric value or expression representing a cash flow value, which must occur at the end of a
period. It is important that the values specified inn2and beyond are in the correct sequence.
The function returns an error if n1 is negative or 0. If any of the parameters are null, the function
returns null.
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
6.5.3. Examples
The following expressions are examples that use the NPV function:
Expression Returns
NPV(0.10, 500, 1500, 4000, 11529.60863329007, which is the net present value of an
10000) investment earning 10% a year that will generate $500, $1500, $4000,
and $10,000 in each of the next four years.
NPV(0.0275 / 12, 50, 60, 273.14193838457, which is the net present value of an investment
40, 100, 25) earning 2.75% year that will generate $50, $60, $40, $100, and $25 in
each of the next five months.
6.6. Pmt
Returns the payment for a loan based on constant payments and a constant interest rate.
67
Financial Functions
NOTE: Interest rate calculation methods differ from country to country. This function calculates an
interest rate based on U.S. interest rate standards.
6.6.1. Syntax
6.6.2. Parameters
Parameter Description
n2 A numeric value or expression representing the interest rate per period of the investment.
The function returns an error if any parameter is negative or 0. If any parameter is null, the function
returns null.
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
6.6.3. Examples
The following expressions are examples that use the Pmt function:
Expression Returns
Pmt(25000, 0.085, 12) 3403.82145169876, which is the annual payment on a $25,000 loan at
8.5% annual interest, repayable over 12 years.
6.7. PPmt
68
Financial Functions 6
NOTE: Interest rate calculation methods differ from country to country. This function calculates an
interest rate based on US interest rate standards.
6.7.1. Syntax
6.7.2. Parameters
Parameter Description
n4 A numeric value or expression representing the first month in which a payment will be made.
n5 A numeric value or expression representing the number of months for which to calculate.
The function returns an error if either of the following conditions are true:
• n1, n2, or n3 are negative or 0.
• Either n4 or n5 is negative.
If any parameter is null, the function returns null. If the payment amount (n3) is less than the
monthly interest load, the function returns0.
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point
numeric values. For more information, see Numberliterals.
6.7.3. Examples
The following expressions are examples that use the PPmt function:
Expression Returns
69
Financial Functions
Expression Returns
PPmt(160000, 0.0475, 4656.19166430515, which is the amount of principal repaid during the
980, 24, 12) third year of the loan.
PPmt(15000, 0.065, 0, because in this case the monthly payment is less than the interest the loan
65.50, 15, 1) accrues during the month, therefore, no part of the principal is repaid.
6.8. PV
Returns the present value of an investment of periodic constant payments at a constant interest rate.
NOTE: Interest rate calculation methods differ from country to country. This function calculates an
interest rate based on U.S. interest rate standards.
6.8.1. Syntax
6.8.2. Parameters
Parameter Description
n2 A numeric value or expression representing the interest per period of the investment.
The function returns an error if either n1 or n3 is negative or 0. If any parameter is null, the function
returns null.
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
6.8.3. Examples
70
Financial Functions 6
Expression Returns
PV(400, 0.10 / 12, 30 * 12) 45580.32799074439. This is the value after 30 years, of a $400 a
month investment growing at 10% annually.
PV(1000, 0.075 / 4, 10 * 4) 58791.96145535981. This is the value after ten years of a $1000 a
month investment growing at 7.5% a quarter.
PV(Payment[0], Int_Rate / This example uses variables in place of actual numeric values or
4, Time) expressions.
6.9. Rate
Returns the compound interest rate per period required for an investment to grow from present to
future value in a given period.
NOTE: Interest rate calculation methods differ from country to country. This function calculates an
interest rate based on U.S. interest rate standards.
6.9.1. Syntax
6.9.2. Parameters
Parameter Description
The function returns an error if any parameter is negative or 0. If any parameter is null, the function
returns null.
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
71
Financial Functions
6.9.3. Examples
The following expressions are examples that use the Rate function:
Expression Returns
Rate(10000, 0.25 * 5000, 4 * 12) 0.04427378243(or 4.43%), which is the interest rate per
month needed for the present value to grow to $10,000 in
four years.
Rate(Target_Value, Pres_Value[*], This example uses variables in place of actual numeric values
Term * 12) or expressions.
6.10. Term
Returns the number of periods needed to reach a given future value from periodic constant
payments into an interest bearing account.
NOTE: Interest rate calculation methods differ from country to country. This function calculates an
interest rate based on U.S. interest rate standards.
6.10.1. Syntax
6.10.2. Parameters
Parameter Description
n1 A numeric value or expression representing the payment amount made at the end of each period.
n2 A numeric value or expression representing the interest rate per period of the investment.
The function returns an error if any parameter is negative or 0. If any parameter is null, the function
returns null.
72
Financial Functions 6
NOTE: FormCalc follows the IEEE-754 international standard when handling floating point numeric
values. For more information, see Numberliterals.
6.10.3. Examples
The following expressions are examples that use the Term function:
Expression Returns
73
Logical Functions
7. Logical Functions
Logical functions are useful for testing and/or analyzing information to obtain a true or false result.
7.1. Choose
7.1.1. Syntax
Choose(n, s1 [, s2 ...])
7.1.2. Parameters
Parameter Description
n The position of the value you want to select within the set. If this value is not a whole number, the
function roundsndown to the nearest whole value.
The function returns an empty string if either of the following conditions is true:
• nis less than 1.
• nis greater than the number of items in the set.
Ifnis null, the function returns null.
7.1.3. Examples
The following expressions are examples that use the Choose function:
Expression Returns
74
Logical Functions 7
Expression Returns
Choose(2, 10, 9, 8, 7, 6, 5, 4, 3, 2, 9
1)
7.2. Exists
7.2.1. Syntax
Exists(v)
7.2.2. Parameters
Parameter Description
7.2.3. Examples
The following expressions are examples that use the Exists function:
Expression Returns
75
Logical Functions
Expression Returns
7.3. HasValue
Determines whether the given parameter is a reference syntax with a non-null, non-empty, or
non-blank value.
7.3.1. Syntax
HasValue(v)
7.3.2. Parameters
Parameter Description
7.3.3. Examples
The following expressions are examples that use the HasValue function.
Expression Returns
HasValue(Amount[* Error
])
HasValue(Amount[0 Evaluates the first occurrence ofAmountand returns true (1) if it is a non-null,
]) non-empty, or non-blank value.
76
Logical Functions 7
7.4. Oneof
7.4.1. Syntax
Oneof(s1, s2 [, s3 ...])
7.4.2. Parameters
Parameter Description
s1 The position of the value you want to select within the set. If this value is not a whole number, the
function roundss1down to the nearest whole value.
7.4.3. Examples
The following expressions are examples that use the Oneof function:
Expression Returns
7.5. Within
77
Logical Functions
7.5.1. Syntax
7.5.2. Parameters
Parameter Description
7.5.3. Examples
The following expressions are examples that use the Within function:
Expression Returns
Within($, 1, 10) True (1) if the current value is between 1 and 10.
78
Miscellaneous Functions 8
8. Miscellaneous Functions
Functions in this section do not fit within any other particular function category and are useful in a
variety of applications.
8.1. Eval
8.1.1. Syntax
Eval(s)
8.1.2. Parameters
Parameter Description
8.1.3. Examples
The following expressions are examples that use the Eval function:
Expression Returns
eval("10*3+5*4") 50
eval("hello") error
79
Miscellaneous Functions
8.2. Null
8.2.1. Definition
Null()
8.2.2. Parameters
None
8.2.3. Examples
The following expressions are examples that use the Null function:
Expression Returns
Null() null
Null() + 5 5
8.3. Ref
8.3.1. Definition
Ref(v)
80
Miscellaneous Functions 8
8.3.2. Parameters
Parameters Description
8.3.3. Examples
The following expressions are examples that use the Ref function:
Expressions Returns
Ref("10*3+5*4") 10*3+5*4
Ref("hello") hello
8.4. UnitType
Returns the units of a unitspan. A unitspan is a string consisting of a number followed by a unit
name.
8.4.1. Syntax
UnitType(s)
81
Miscellaneous Functions
8.4.2. Parameters
Parameter Description
s A valid string containing a numeric value and a valid unit of measurement (unitspan). Recognized
units of measurement are:
• in, inches
• mm, millimeters
• cm, centimeters
• pt, points
• pc, picas
• mp, millipoints
Ifsis invalid, the function returnsin.
8.4.3. Examples
The following expressions are examples that use the UnitType function:
Expression Results
UnitType("36 in") in
UnitType("2.54centimeters") cm
UnitType("picas") pc
UnitType("2.cm") cm
UnitType("2.zero cm") in
UnitType("kilometers") in
82
Miscellaneous Functions 8
8.5. UnitValue
Returns the numerical value of a measurement with its associated unitspan, after an optional unit
conversion. A unitspan is a string consisting of a number followed by a valid unit of measurement.
8.5.1. Syntax
UnitValue(s1 [, s2 ])
8.5.2. Parameters
Parameters Description
s1 A valid string containing a numeric value and a valid unit of measurement (unitspan). Recognized
units of measurement are:
• in, inches
• mm, millimeters
• cm, centimeters
• pt, picas, points
• mp, millipoints
s2(optional) A string containing a valid unit of measurement. The function converts the unitspan specified
ins1to this new unit of measurement.
If you do not include a value fors2, the function uses the unit of measurement specified ins1.
Ifs2is invalid, the function converts s1into inches.
8.5.3. Examples
The following expressions are examples that use the UnitValue function:
Expression Returns
UnitValue("2in") 2
83
Miscellaneous Functions
Expression Returns
UnitValue("A", "cm") 0
UnitValue("5.08cm", 2
"kilograms")
84
String Functions 9
9. String Functions
String functions deal with the manipulation, evaluation, and creation of string values.
9.1. At
9.1.1. Syntax
At(s1, s2)
9.1.2. Parameters
Parameter Description
9.1.3. Examples
Expression Returns
At("ABCDEFGH", "AB") 1
At("ABCDEFGH", "F") 6
85
String Functions
9.2. Concat
9.2.1. Syntax
Concat(s1 [, s2 ...])
9.2.2. Parameters
Parameter Description
9.2.3. Examples
The following expressions are examples that use the Concat function:
Expression Returns
Concat("You owe ", You owe One Thousand One Hundred Fifty-four
WordNum(1154.67, 2), ".") Dollars And Sixty-seven Cents.
See also WordNum.
9.3. Decode
86
String Functions 9
9.3.1. Syntax
Decode(s1 [, s2 ])
9.3.2. Parameters
Parameter Description
s2(Optional) A string identifying the type of decoding to perform. The following strings are valid decoding
strings:
• url (URL decoding)
• html (HTML decoding)
• xml (XML decoding)
If you do not include a value fors2, the function uses URL decoding.
9.3.3. Examples
The following expressions are examples that use the Decode function:
Expression Returns
Decode("ÆÁÂÁ ÆÁÂÁÂ
Â", "html")
Decode("~!@#$%^&*()_+|`{"}[] ~!@#$%^&*()_+|`{""}[]<>?,./;':
<>?,./;':", "xml")
9.4. Encode
9.4.1. Syntax
Encode(s1 [, s2 ])
87
String Functions
9.4.2. Parameters
Parameter Description
s2(Optional) A string identifying the type of encoding to perform. The following strings are valid encoding
strings:
• url (URL encoding)
• html (HTML encoding)
• xml (XML encoding)
If you do not include a value fors2, the function uses URL encoding.
9.4.3. Examples
The following expressions are examples that use the Encode function:
Expression Returns
9.5. Format
Formats the given data according to the specified picture format string.
9.5.1. Syntax
Format(s1, s2 [, s3 ...])
88
String Functions 9
9.5.2. Parameters
Parameter Description
s1 The picture format string, which may be a locale-sensitive date or time format.
See Locales.
89
String Functions
9.5.3. Examples
The following expressions are examples that use the Format function:
Expression Returns
9.6. Left
Extracts a specified number of characters from a string, starting with the first character on the left.
9.6.1. Syntax
Left(s, n)
9.6.2. Parameters
Parameter Description
9.6.3. Examples
The following expressions are examples that use the Left function:
90
String Functions 9
Expression Returns
Left("ABCDEFGH", 3) ABC
9.7. Len
9.7.1. Syntax
Len(s)
9.7.2. Parameters
Parameter Description
9.7.3. Examples
The following expressions are examples that use the Len function:
Expression Returns
Len("ABDCEFGH") 8
Len(4) 1
Len(Str(4.532, 6, 4)) 6
See also Str.
91
String Functions
Expression Returns
9.8. Lower
9.8.1. Syntax
Lower(s, [, k ])
9.8.2. Parameters
Parameter Description
k(Optional) A string representing a valid locale. If you do not include a value for k, the function uses the
ambient locale.
See Locales.
This function only converts the Unicode characters U+41 through U+5A (of the ASCII character
set) as well as the characters U+FF21 through U+FF3A (of the fullwidth character set)
9.8.3. Examples
The following expressions are examples that use the Lower function:
Expression Returns
Lower("ABC") abc
Lower(15) 15
Lower(Address[0]) This example converts the first occurrence ofAddressto all lowercase letters.
92
String Functions 9
9.9. Ltrim
9.9.1. Syntax
Ltrim(s)
9.9.2. Parameters
Parameter Description
9.9.3. Examples
The following expressions are examples that use the Ltrim function:
Expression Returns
9.10. Parse
93
String Functions
9.10.1. Syntax
Parse(s1, s2 )
9.10.2. Parameters
Parameter Description
9.10.3. Examples
The following expressions are examples that use the Parse function:
Expression Returns
9.11. Replace
Replaces all occurrences of one string with another within a specified string.
9.11.1. Syntax
Replace(s1, s2 [, s3 ])
94
String Functions 9
9.11.2. Parameters
Parameter Description
s1 A source string.
9.11.3. Examples
The following expressions are examples that use the Replace function:
Expression Returns
9.12. Right
Extracts a number of characters from a given string, beginning with the last character on the right.
9.12.1. Syntax
Right(s, n )
95
String Functions
9.12.2. Parameters
Parameter Description
9.12.3. Examples
The following expressions are examples that use the Right function:
Expression Returns
Right("ABCDEFGH", 3) FGH
9.13. Rtrim
9.13.1. Syntax
Rtrim(s )
96
String Functions 9
9.13.2. Parameters
Parameter Description
9.13.3. Examples
The following expressions are examples that use the Rtrim function:
Expression Returns
Rtrim(Address[0]) Removes any trailing white space from the first occurrence
ofAddress.
9.14. Space
9.14.1. Syntax
Space(n )
9.14.2. Parameters
Parameter Description
97
String Functions
9.14.3. Examples
The following expressions are examples that use the Space function:
Expression Returns
Space(Max(Amount[*])) A blank string with as many characters as the value of the largest
occurrence ofAmount.
See also Max.
9.15. Str
Converts a number to a character string. FormCalc formats the result to the specified width and
rounds to the specified number of decimal places.
9.15.1. Syntax
Str(n1 [, n2 [, n3 ]])
9.15.2. Parameters
Parameter Description
n2(Optional) The maximum width of the string. If you do not include a value forn2, the function uses a value
of10as the default width.
If the resulting string is longer thann2, the function returns a string of * (asterisk) characters of
the width specified byn2.
n3(Optional) The number of digits to appear after the decimal point. If you do not include a value forn3, the
function uses 0 as the default precision.
98
String Functions 9
9.15.3. Examples
The following expressions are examples that use the Str function:
Expression Returns
Str(4.532, 6, 4) 4.5320
Str(31.2345, 4, 2) ****
Str(Max(Amount[*]), 6, Converts the largest occurrence ofAmountto a six-character string with two
2) decimal places.
See also Max.
9.16. Stuff
9.16.1. Syntax
Stuff(s1, n1, n2 [, s2 ])
9.16.2. Parameters
Parameter Description
n2 The number of characters to delete from strings1, starting at character position n1.
Ifn2is less than or equal to 0, the function assumes 0 characters.
99
String Functions
9.16.3. Examples
The following expressions are examples that use the Stuff function:
Expression Returns
Stuff("ABCDEFGH", 4, 2) ABCFGH
Stuff(Address[0], Len(Address[0]), This adds the wordStreetonto the end of the first
0, "Street") occurrence ofAddress.
See also Len.
Stuff("[email protected]", 0, cc:[email protected]
0, "cc:"
9.17. Substr
9.17.1. Syntax
Substr(s1, n1, n2 )
9.17.2. Parameters
Parameter Description
100
String Functions 9
9.17.3. Examples
The following expressions are examples that use the Substr function:
Expression Returns
Substr("ABCDEFG", 3, 4) CDEF
Substr(3214, 2, 1) 2
Substr(Last_Name[0], 1, 3) Returns the first three characters from the first occurrence
ofLast_Name.
Substr("ABCDEFG", 5, 0) ""
9.18. Uuid
9.18.1. Syntax
Uuid([n ])
9.18.2. Parameters
Parameter Description
n A number identifying the format of the UUID string. Valid numbers are:
• 0 (default value): UUID string only contains hex octets.
• 1: UUID string contains dash characters separating the sequences of hex octets
at fixed positions.
If you do not include a value for n, the function uses the default value.
101
String Functions
9.18.3. Examples
Expression Returns
9.19. Upper
9.19.1. Syntax
Upper(s [, k ])
9.19.2. Parameters
Parameter Description
k(Optional) A string representing a valid locale. If you do not include a value for k, the ambient locale is used.
This function only converts the Unicode characters U+61 through U+7A (of the ASCII character
set) as well as the characters U+FF41 through U+FF5A (of the fullwidth character set).
9.19.3. Examples
The following expressions are examples that use the Upper function:
102
String Functions 9
Expression Returns
Upper("abc") ABC
Upper(15) 15
Upper(Address[0]) This example converts the first occurrence ofAddressto all uppercase letters.
9.20. WordNum
Returns the English text equivalent of a given number.
9.20.1. Syntax
WordNum(n1 [, n2 [, k ]])
9.20.2. Parameters
Parameter Description
103
String Functions
Parameter Description
k(Optional) A string representing a valid locale. If you do not include a value fork, the function uses the
ambient locale.
See Locales.
As of this release, it is not possible to specify a locale identifier other than English for this
function.
9.20.3. Examples
The following expressions are examples that use the WordNum function.
Expression Returns
WordNum(Amount[0], 2) This example uses the first occurrence ofAmountas the conversion number.
104
URL Functions 10
10.1. Get
10.1.1. Syntax
Get(s)
10.1.2. Parameters
Parameter Description
10.1.3. Examples
The following expressions are examples that use the Get function.
Expression Returns
105
URL Functions
10.2. Post
10.2.1. Syntax
Post(s1, s2 [, s3 [, s4 [, s5 ]]])
10.2.2. Parameters
Parameter Description
s3(Optional) A string containing the content type of the data to post. Here are valid content types:
• application/octet-stream (default value)
• text/html
• text/xml
• text/plain
• multipart/form-data
• application/x-www-form-urlencoded
• Any other valid MIME type
If you do not include a value fors3, the function sets the content type to the default value. The
application ensures that the data to post uses the correct format according to the specified content
type.
106
URL Functions 10
Parameter Description
s4(Optional) A string containing the name of the code page used to encode the data. Here are valid code page
names:
• UTF-8 (default value)
• UTF-16
• ISO-8859-1
• Any character encoding listed by the Internet Assigned Numbers Authority
(IANA)
If you do not include a value fors4, the function sets the code page to the default value. The
application ensures that encoding of the data to post matches the specified code page.
s5(Optional) A string containing any additional HTTP headers to be included with the posting of the data.
If you do not include a value fors5, the function does not include an additional HTTP header in the
post.
SOAP servers usually require a SOAPAction header when posting to them.
10.2.3. Examples
The following expressions are examples that use the Post function:
Expression Returns
Post("http://www.nanonull.com/TimeServ Posts a SOAP request for the local time to some server,
ice/ expecting an XML response back.
TimeService.asmx/getLocalTime", "<?xml
version='1.0'
encoding='UTF-8'?><soap:Envelope><soap
:Body>
<getLocalTime/></soap:Body>
</soap:Envelope>", "text/xml",
"utf-8",
"http://www.Nanonull.com/TimeService/g
etLocalTime")
107
URL Functions
10.3. Put
10.3.1. Syntax
Put(s1, s2 [, s3 ])
10.3.2. Parameters
Parameter Description
s3(Optional A string containing the name of the code page used to encode the data. Here are valid code page
) names:
• UTF-8 (default value)
• UTF-16
• ISO8859-1
• Any character encoding listed by the Internet Assigned Numbers Authority
(IANA)
If you do not include a value fors3, the function sets the code page to the default value. The
application ensures that encoding of the data to upload matches the specified code page.
10.3.3. Examples
108
URL Functions 10
Expression Returns
Put("ftp://www.example.com/pub/fubu. Nothing if the FTP server has permitted the user to upload
xml", some XML data to thepub/fubu.xmlfile. Otherwise,
"<?xml version='1.0' this function returns an error.
encoding='UTF-8'?><msg>hello
world!</msg>")
NOTE: This example only works in the server environment and not in Acrobat or Adobe Reader. For
forms displayed in Acrobat and Adobe Reader, use the HTTP, HTTPS, and FILE protocols.
109