// Declaration of integer z integer z // Assignment statement z=x+y
x<=y
// declarations integer x; /*semicolon is safely ignored, and can use C-style comments*/ real y // statements x=10 y=12.4 /* more than one statement can be on a line */
["static"]["private"|"public"]["hidden"|"visible"] type[(*size)] ["array"] identifier
"integer"|"string"|"real"|"boolean"|"date"
string `my var` `my var`="Hello"
// a 30-character string available // only to the code block private string(30) name // a 30-byte string string(30 bytes) name // a 255-character public string string address // a global real number global real number // a public date field. Use back // quotes if symbols include spaces date `birth date`
statement: | "goto" label | identifier "=" expression | "return" expression | "if" expression ["then"] statement ["else" statement] | "for" identifier ["="] expression ["to"] expression ["step" expression] statement | "begin" statement [statement...] "end" | ["call"] function | "while" expression statement label: identifier ":" expression: described later function: identifier "(" parameter [,parameter...] ")"
integer num string str date dt boolean b real r // assign 1 to num num=1 // assign Jan 28 '03 to the date symbol dt=#01/28/03# // sets boolean to true b=true // also sets boolean to true b='yes' // sets real to 30.12 (converting from string) r="30.12" // sets string to the string representation of the date str=dt // sets num to the rounded value of r num=r
// only include rows where ID >= 200 if id < 200 return false
string(20) person integer x integer y integer age Age=10 if Age < 20 then person="child" else person="adult" if Age==10 begin x=50 y=20 end // nested if/else if Age <= 60 if Age < 40 call print("Under 40") // this else corresponds to the inner if statement else call print("Age 40 to 60") // this else corresponds to the outer if statement else call print("Over 60")
integer i for i = 1 to 10 step 2 call print('Value of i is ' & i) integer x integer y x=10 y=20 for i = x to y call print('Value of i is ' & i) for i = y to x step -1 begin call print('Value of i is ' & i) x=i /*does not affect the loop since start/end/step expressions are only evaluated before loop*/ end
integer i i=1000 // keep looping while the value of i is > 10 while i > 10 i=i/2 // you can use begin/end to enclose more than one statement while i < 1000 begin i=i*2 call print('Value if i is ' & i) end
Operators
|
Description
|
---|---|
! or not
|
Boolean
|
(,)
|
parentheses (can be
nested to any depth)
|
*
|
multiply
|
/
|
divide
|
%
|
modulo
|
+
|
add
|
-
|
subtract
|
&
|
string concatenation
|
!=
|
not equal ("!="
and "<>" are the same)
|
<>
|
not equal
|
==
|
comparison operator
(= is an assignment and should not be used for comparisons)
|
>
|
greater than
|
<
|
less than
|
>=
|
greater than or equal
to
|
<=
|
less than or equal to
|
and
|
Boolean and
|
or
|
Boolean or
|
a%d
("a modulo d
") returns
a value r, for example:
a = qd + r and 0 ≤ r < | d |, where | d | denotes the absolute value of d
a
or d
are not integers,
they are rounded down to the nearest integer before the modulo calculation
is performed.
a
and d
, it can be the remainder
on division of a
by d
. For example:
string str // simple string str="Hello" // concatenate two strings str="Hello" & " There"
date date_value1 date data_value2 date_value1 = todate("01/02/03") date_value2 = #01-02-03#
boolean a boolean b boolean c a=true b=false // c is true c=a or b // c is false c=a and b // c is true c=10<20 // c is false c=10==20 // c is true c=10!=20 // c is true c='yes' // c is false c='no'
Expression
|
Result
|
---|---|
null == value
|
null (applies to all
comparison operators)
|
null & string
|
string
|
null & null
|
null
|
number + null
|
null (applies to all
arithmetic operations)
|
null + null
|
null (applies to all
arithmetic operations)
|
null AND null
|
null
|
null AND true
|
null
|
null AND false
|
false
|
null OR null
|
null
|
null OR true
|
true
|
null OR false
|
false
|
not null
|
null
|
if null
|
statement following
if is not executed
|
FOR loop
|
run-time error if any
of the terms are null
|
while null
|
statement following
while is not executed
|
integer x integer y integer z boolean b string s x=10 y=null // z has a value of null z=x + y // b is true b=true or null // b is null b=false or null // use isnull function to determine if null if isnull(b) call print("B is null") // s is "str" s="str" & null
toreal(xyz) > 123.456
Coercion Type
|
TOSTRING
|
TOINTEGER
|
TOREAL
|
TODATE
|
TOBOOLEAN
|
---|---|---|---|---|---|
from String
|
|
yes
|
yes
|
yes
|
yes
|
from Integer
|
yes
|
|
yes
|
yes
|
yes
|
from Real
|
yes
|
yes
|
|
yes
|
yes
|
from Date
|
yes
|
yes
|
yes
|
|
no
|
from Boolean
|
yes
|
yes
|
yes
|
no
|
|
Coercion Type
|
Resulting Action
|
---|---|
date to string
|
A default date format
is used: YYYY/MM/DD hh:mm:ss. Use the FORMATDATE function for a more
flexible conversion.
|
date to number
|
The number represents
days since 12/30/1899. Hours, minutes, seconds, and milliseconds are
converted to a fraction, where 1 hour = 1/24 units, 1 minute = 1/(24*60)
units, and so on.
|
string to date
|
Most date formats are
recognized and intelligently converted. See the Date Expressions section
for more information.
|
string to Boolean
|
The values yes, no,
true, false, y, n, t, and f are recognized.
|
integer to real to Boolean
|
Any nonzero value is
true. Zero is false.
|
string str integer x str="Hello there" // calls the upper function if upper(str)=='HELLO THERE' // calls the print function call print("yes") // x is set to 7 (position of word 'there') x=instr(str,"there",1)
function example_udf return string 255 // this function is declared to return a string of // up to 255 characters retrieve the number of // parameters passed print("You passed " & parametercount() & " parameters") integer x for x = 1 to parametercount() begin print("Parameter " & x & " type is " & parametertype(x) & " value is " & parameter(x)) if(parametertype(x)=="integer") print("Integer: " & parameterinteger(x)) else if parametertype(x)=="real" print("Real: " & parameterreal(x)) end return "string val" end function