|
ION Script User's Guide: Variables, Expressions & Operators |
|
An expression is a combination of values, variables, and/or other expressions separated by operators, or simply a single value or variable.
The following are examples of expressions:
|
'Friday'
|
1 + 3
|
|
$A + $B
|
4.0
|
|
$E = $M * $C^2
|
$String1 EQ $String2
|
|
$Browser.type
|
$Variable = 4 + 3
|
|
$Form.name
|
$X = $A + $B
|
|
$Variable = (34 GE 341)
|
$LastName = 'Smith'
|
Values used in expressions can be any of the following:
There are three main types of expressions. They are:
Numeric expressions are expressions that evaluate to a number. The following are examples of numeric expressions:
Numbers can be one of two types: DOUBLE (double precision, such as 1.2345) or INT (integer, such as 1).
All numeric expressions are evaluated as double-precision values, regardless of whether the variables or values in the expression are integers or double-precision values. For example, if you declare variables A and B as integers, the result of $A+$B will be a double. If, however, you assign the result of $A+$B to a variable that was declared as an integer, then the result will be an integer.
| Note ION Script uses the C printf conversion specifier %g with 16 significant digits when displaying double-precision values. If, when converted to scientific notation, the value's exponent is less than -4 or greater than 16, the value will be displayed using scientific notation. Otherwise, the value is printed as a floating-point value. Trailing zeros in the fractional part of the value are not printed. |
Boolean expressions are expressions that return a boolean value, that is, true or false. The values used in the expression are numbers or strings. The operators that return boolean values are:
GT, GE, LT, LE, EQ, NE, ISTYPE, AND, OR, NOT
The following are examples of boolean expressions:
If you declare a variable as a BOOL, and then later reassign it a numeric value, the variable is assigned a value of FALSE if the expression evaluates to zero, and TRUE otherwise. For example, if $C was declared as type BOOL, and later reassigned the value $C = $A + $B, then $C would be assigned the value FALSE if $A + $B evaluates to 0, and TRUE if $A + $B evaluates to anything other than 0.
String expressions are expressions that return strings. Strings can be used with five operators: EQ, NE, +, CONTAINS, and ISTYPE. The + operator is used to concatenate, or combine, two strings. For example, the expression 'Hello' + ' World!' yields 'Hello World!'.
The following are examples of string expressions:
Note that $Name in the above examples must be a string.
If you declare a variable as type string and assign it a numeric value, the number will be converted to double-precision and then to a string. For example, the following code creates a string variable and assigns the value 35.4:
<VARIABLE_DECL NAME="A" VALUE="35.4" TYPE="STR"/>
If you write the value of this variable to the page, it will read as 35.40 instead of 35.4. To prevent the number from being converted to a double-precision value, enclose it in single quotation marks as follows:
<VARIABLE_DECL NAME="A" VALUE=" '35.4' " TYPE="STR"/>
IDL Online Help (March 06, 2007)