IB Statements/operations
From CometWiki
(New page: The Internet Basic language supports the following types of operations: Numeric Operations String Operations Relational Operations Logical Operations In addition to these operations, the...) |
|||
(17 intermediate revisions not shown) | |||
Line 1: | Line 1: | ||
The Internet Basic language supports the following types of operations: | The Internet Basic language supports the following types of operations: | ||
- | Numeric Operations | + | * Numeric Operations |
- | String Operations | + | * String Operations |
- | Relational Operations | + | * Relational Operations |
- | Logical Operations | + | * Logical Operations |
- | + | ===Numeric Operations=== | |
- | + | ||
- | + | ||
- | Numeric Operations | + | |
- | + | ||
The following types of operations may be performed on numeric data: | The following types of operations may be performed on numeric data: | ||
- | Addition | + | * Addition |
- | Subtraction | + | * Subtraction |
- | Multiplication | + | * Multiplication |
- | Division | + | * Division |
- | Modulo | + | * Modulo |
Also see the notes about Precedence. | Also see the notes about Precedence. | ||
+ | ====Addition==== | ||
+ | The plus sign '''(+)''' is the operator used to perform addition on numeric data. | ||
- | + | Notes: If the result of an addition operation exceeds the defined length of a receiving numeric variable, the value will be truncated on the left-hand side without warning. | |
- | + | If the precision of the result exceeds the defined precision of a receiving variable (and the variable has not been defined for automatic rounding), the result will be truncated on the right-hand side. See the ROUND statement for more information. | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | If the precision of the result exceeds the defined precision | + | |
Also see the LET statement. | Also see the LET statement. | ||
Example: | Example: | ||
- | + | <pre> | |
LENGTH 5.0 ! Declare the length for A, B, C | LENGTH 5.0 ! Declare the length for A, B, C | ||
LOCAL A, B, C ! Declare them as LOCAL variables | LOCAL A, B, C ! Declare them as LOCAL variables | ||
Line 40: | Line 32: | ||
LET B = 2000 ! Set the value for B | LET B = 2000 ! Set the value for B | ||
LET C = A + B ! Add A and B, giving C | LET C = A + B ! Add A and B, giving C | ||
+ | </pre> | ||
+ | ====Subtraction==== | ||
- | + | The minus sign '''(-)''' is the operator used to perform subtraction on numeric data. | |
- | + | Notes: If the result of a subtraction operation exceeds the defined length of a receiving numeric variable, the value will be truncated on the left-hand side without warning. | |
- | + | ||
- | Notes: | + | |
- | + | ||
- | If the result of a subtraction operation exceeds the defined | + | |
If the precision of the result exceeds the defined precision of a receiving variable (and the variable has not been defined for automatic rounding), the result will be truncated on the right-hand side. See the ROUND statement for more information. | If the precision of the result exceeds the defined precision of a receiving variable (and the variable has not been defined for automatic rounding), the result will be truncated on the right-hand side. See the ROUND statement for more information. | ||
Line 54: | Line 44: | ||
Example: | Example: | ||
- | + | <pre> | |
LENGTH 5.0 ! Declare the length for A, B, C | LENGTH 5.0 ! Declare the length for A, B, C | ||
LOCAL A, B, C ! Declare them as LOCAL variables | LOCAL A, B, C ! Declare them as LOCAL variables | ||
Line 61: | Line 51: | ||
LET B = 200 ! Set the value for B | LET B = 200 ! Set the value for B | ||
LET C = A - B ! Subtract B from A, giving C | LET C = A - B ! Subtract B from A, giving C | ||
+ | </pre> | ||
+ | ====Multiplication==== | ||
- | + | The asterisk '''(*)''' is the operator used to perform multiplication on numeric data. | |
- | + | Notes: If the result of a multiplication operation exceeds the defined length of a receiving numeric variable, the value will be truncated on the left-hand side without warning. | |
- | + | If the precision of the result exceeds the defined precision of a receiving variable (and the variable has not been defined for automatic rounding), the result will be truncated on the right-hand side. See the ROUND statement for more information. | |
- | + | ||
- | + | ||
- | + | ||
- | If the precision of the result exceeds the defined precision | + | |
Also see the LET statement. | Also see the LET statement. | ||
Example: | Example: | ||
- | + | <pre> | |
LENGTH 5.0 ! Declare the length for A, B, C | LENGTH 5.0 ! Declare the length for A, B, C | ||
LOCAL A, B, C ! Declare them as LOCAL variables | LOCAL A, B, C ! Declare them as LOCAL variables | ||
Line 82: | Line 70: | ||
LET B = 25 ! Set the value for B | LET B = 25 ! Set the value for B | ||
LET C = A * B ! Multiply A and B, giving C | LET C = A * B ! Multiply A and B, giving C | ||
+ | </pre> | ||
+ | ====Division==== | ||
- | + | The backslash '''(/)''' is the operator used to perform division on numeric data. | |
- | + | Notes: If the result of a division operation exceeds the defined length of a receiving numeric variable, the value will be truncated on the left-hand side without warning. | |
- | + | If the precision of the result exceeds the defined precision of a receiving variable (and the variable has not been defined for automatic rounding), the result will be truncated on the right-hand side. See the ROUND statement for more information. | |
- | + | ||
- | + | ||
- | + | ||
- | If the precision of the result exceeds the defined precision | + | |
Also see the LET statement. | Also see the LET statement. | ||
Example: | Example: | ||
- | + | <pre> | |
LENGTH 5.0 ! Declare the length for A, B, C | LENGTH 5.0 ! Declare the length for A, B, C | ||
LOCAL A, B, C ! Declare them as LOCAL variables | LOCAL A, B, C ! Declare them as LOCAL variables | ||
Line 103: | Line 89: | ||
LET B = 25 ! Set the value for B | LET B = 25 ! Set the value for B | ||
LET C = A / B ! Divide A by B, giving C | LET C = A / B ! Divide A by B, giving C | ||
- | + | </pre> | |
- | Modulo | + | ====Modulo==== |
The MOD operator performs a modulo operation on the two numeric values (i.e., it divides the first value by the second value and returns the remainder). | The MOD operator performs a modulo operation on the two numeric values (i.e., it divides the first value by the second value and returns the remainder). | ||
- | The MOD operator is supported in Comet 504 and greater. | + | The MOD operator is supported in Comet 504 and greater. In <u>Comet32</u> you may use either MOD or % as the operator. |
The syntax is: | The syntax is: | ||
Line 114: | Line 100: | ||
numeric-value-1 MOD numeric-value-2 | numeric-value-1 MOD numeric-value-2 | ||
Example: | Example: | ||
+ | <pre> | ||
+ | LET C = 10 MOD 3 | ||
+ | </pre> | ||
+ | This operation returns a value of 1 as 10 divided by 3 equals 3 with a <u>remainder</u> of 1. | ||
- | + | ====Precedence==== | |
- | + | ||
- | + | ||
- | Precedence | + | |
In a numeric expression containing multiple operations, the multiplication and division operations are performed first (from left to right). Next, the addition and subtraction operations are performed (also from left to right). | In a numeric expression containing multiple operations, the multiplication and division operations are performed first (from left to right). Next, the addition and subtraction operations are performed (also from left to right). | ||
Line 124: | Line 111: | ||
This algebraic order can be overridden with parentheses. In a numeric expression containing parentheses, operations inside the parentheses will be performed first, followed by the algebraic order previously described. Parentheses may be nested to any level in a numeric expression -- they will be performed from the inside to the outside. | This algebraic order can be overridden with parentheses. In a numeric expression containing parentheses, operations inside the parentheses will be performed first, followed by the algebraic order previously described. Parentheses may be nested to any level in a numeric expression -- they will be performed from the inside to the outside. | ||
- | Results | + | ====Results==== |
The temporary result of a numeric operation will contain only as many digits to the right of the decimal point as the most precise operand in the expression. For example, if an expression contains operand with two digits of precision and four digits of precision, the temporary result will contain four digits of precision. | The temporary result of a numeric operation will contain only as many digits to the right of the decimal point as the most precise operand in the expression. For example, if an expression contains operand with two digits of precision and four digits of precision, the temporary result will contain four digits of precision. | ||
- | String | + | ==String Operation (Concatenation)== |
The Internet Basic language supports the string operation of concatenation. The plus sign (+) is used to indicate concatenation (the combining of strings). For example, concatenating two string variables would look like this: | The Internet Basic language supports the string operation of concatenation. The plus sign (+) is used to indicate concatenation (the combining of strings). For example, concatenating two string variables would look like this: | ||
- | + | <pre> | |
FIRSTNAME$ + LASTNAME$ | FIRSTNAME$ + LASTNAME$ | ||
+ | </pre> | ||
You may concatenate string constants, string variables, and string functions. Here is an example of concatenating constants with variables: | You may concatenate string constants, string variables, and string functions. Here is an example of concatenating constants with variables: | ||
- | + | <pre> | |
"(" + AREACODE$ + ")" + PHONENUMBER$ | "(" + AREACODE$ + ")" + PHONENUMBER$ | ||
- | + | </pre> | |
+ | The maximum number of characters in a string is 254. If a concatenation operation results in more characters than have been declared for a receiving variable, characters will be truncated on the right-hand side. THIS TRUNCATION WILL OCCUR WITHOUT WARNING OF ANY KIND. | ||
- | Relational | + | ==Relational Operation (IF/THEN/ELSE)== |
- | The Internet Basic language supports relational operations in IF/THEN statements. The following operations are supported: | + | The Internet Basic language supports relational operations in IF/THEN statements.<br/> The following operations are supported: |
+ | {| border = "1" cell padding="30" align = "center" | ||
+ | !Operation | ||
+ | !Internet Basic syntax | ||
+ | |- | ||
+ | |Equal to ||EQ or = | ||
+ | |- | ||
+ | |Not equal to||NE or NOT= | ||
+ | |- | ||
+ | |Greater than||GT or > | ||
+ | |- | ||
+ | |Greater than or equal to||GE or >= | ||
+ | |- | ||
+ | |Less than||LT or < | ||
+ | |- | ||
+ | |Less than or equal to||LE or <= | ||
+ | |- | ||
+ | |Contains||Contains | ||
+ | |- | ||
+ | |Soundslike||Soundslike | ||
+ | |} | ||
- | + | Two strings are considered to be equal only when they are identical and have the <u>same current length</u> (number of characters). | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | When comparing string values, the ASCII values for the characters are compared. For example, upper case "A" is less than lower case "a" because the ASCII value for "A" (65) is less than the ASCII value for "a" (97). See ASCII chart [http://signature.net/ib/ascii.htm] | |
- | + | The Contains operator will be true when the left hand string operand contains the right hand string operand.<br/> | |
+ | The Soundslike operator will be true when the soundex key of both operands are equal. See [http://www.archives.gov/genealogy/census/soundex.html]<br/> | ||
+ | Both the Contains and Soundslike operators are case '''insensitive'''. | ||
- | + | ==Logical Operations== | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | Logical Operations | + | |
The Internet Basic language supports the AND and OR logical operations to be used in conjunction with relational expressions. The AND operator tests whether both relational conditions are true, while the OR operator tests for truth of either relational condition. For example: | The Internet Basic language supports the AND and OR logical operations to be used in conjunction with relational expressions. The AND operator tests whether both relational conditions are true, while the OR operator tests for truth of either relational condition. For example: | ||
- | + | <pre> | |
IF A=B AND B=C THEN... ! Both conditions must be true | IF A=B AND B=C THEN... ! Both conditions must be true | ||
IF A=B OR B=C THEN... ! Either condition may be true | IF A=B OR B=C THEN... ! Either condition may be true | ||
+ | </pre> | ||
If AND and OR are combined in a relational expression, the AND operator takes precedence (i.e., it will be evaluated first). It is possible to override this precedence with parentheses, just like the precedence in numeric operations can be overridden. | If AND and OR are combined in a relational expression, the AND operator takes precedence (i.e., it will be evaluated first). It is possible to override this precedence with parentheses, just like the precedence in numeric operations can be overridden. | ||
- | For more information on relational operations and logical operations, see the IF statement. | + | For more information on relational operations and logical operations, see the [[IF]] statement. |
Beginning with Comet 2004, logical operations are also supported on binary expressions. The AND, OR, and XOR operators are available. | Beginning with Comet 2004, logical operations are also supported on binary expressions. The AND, OR, and XOR operators are available. | ||
+ | |||
The AND operator performs a logical conjunction on two expressions. AND compares identically positioned bits in two numeric expressions and sets the corresponding bit in the result field. A result bit will only be set to 1 if both of the corresponding bits in the expression fields are 1. Otherwise the result bit will be 0. | The AND operator performs a logical conjunction on two expressions. AND compares identically positioned bits in two numeric expressions and sets the corresponding bit in the result field. A result bit will only be set to 1 if both of the corresponding bits in the expression fields are 1. Otherwise the result bit will be 0. | ||
For example: | For example: | ||
+ | <pre> | ||
C = A AND B | C = A AND B | ||
If A = 1010 (binary) and B = 0011 (binary), then C = 0010 (binary). | If A = 1010 (binary) and B = 0011 (binary), then C = 0010 (binary). | ||
- | + | </pre> | |
The OR operator performs a logical disjunction on two numeric expressions. OR compares identically positioned bits in two numeric expressions and sets the corresponding bit in the result field. A result bit will always be set to 1 unless the corresponding bits in both expression fields are 0. | The OR operator performs a logical disjunction on two numeric expressions. OR compares identically positioned bits in two numeric expressions and sets the corresponding bit in the result field. A result bit will always be set to 1 unless the corresponding bits in both expression fields are 0. | ||
For example: | For example: | ||
+ | <pre> | ||
C = A OR B | C = A OR B | ||
If A = 1010 (binary) and B = 0011 (binary), then C = 1011 (binary). | If A = 1010 (binary) and B = 0011 (binary), then C = 1011 (binary). | ||
- | + | </pre> | |
The XOR operator performs a logical exclusion on two numeric expressions. XOR compares identically positioned bits in two numeric expressions and sets the corresponding bit in the result field. A result bit will only be set to 1 if exactly one of the expression fields has a 1 bit set in the corresponding position. | The XOR operator performs a logical exclusion on two numeric expressions. XOR compares identically positioned bits in two numeric expressions and sets the corresponding bit in the result field. A result bit will only be set to 1 if exactly one of the expression fields has a 1 bit set in the corresponding position. | ||
For example: | For example: | ||
+ | <pre> | ||
C = A XOR B | C = A XOR B | ||
If A = 1010 (binary) and B = 0011 (binary), then C = 1001 (binary). | If A = 1010 (binary) and B = 0011 (binary), then C = 1001 (binary). | ||
+ | </pre> |
Latest revision as of 21:33, 18 January 2011
The Internet Basic language supports the following types of operations:
- Numeric Operations
- String Operations
- Relational Operations
- Logical Operations
Contents |
Numeric Operations
The following types of operations may be performed on numeric data:
- Addition
- Subtraction
- Multiplication
- Division
- Modulo
Also see the notes about Precedence.
Addition
The plus sign (+) is the operator used to perform addition on numeric data.
Notes: If the result of an addition operation exceeds the defined length of a receiving numeric variable, the value will be truncated on the left-hand side without warning.
If the precision of the result exceeds the defined precision of a receiving variable (and the variable has not been defined for automatic rounding), the result will be truncated on the right-hand side. See the ROUND statement for more information.
Also see the LET statement.
Example:
LENGTH 5.0 ! Declare the length for A, B, C LOCAL A, B, C ! Declare them as LOCAL variables . LET A = 500 ! Set the value for A LET B = 2000 ! Set the value for B LET C = A + B ! Add A and B, giving C
Subtraction
The minus sign (-) is the operator used to perform subtraction on numeric data.
Notes: If the result of a subtraction operation exceeds the defined length of a receiving numeric variable, the value will be truncated on the left-hand side without warning.
If the precision of the result exceeds the defined precision of a receiving variable (and the variable has not been defined for automatic rounding), the result will be truncated on the right-hand side. See the ROUND statement for more information.
Also see the LET statement.
Example:
LENGTH 5.0 ! Declare the length for A, B, C LOCAL A, B, C ! Declare them as LOCAL variables . LET A = 800 ! Set the value for A LET B = 200 ! Set the value for B LET C = A - B ! Subtract B from A, giving C
Multiplication
The asterisk (*) is the operator used to perform multiplication on numeric data.
Notes: If the result of a multiplication operation exceeds the defined length of a receiving numeric variable, the value will be truncated on the left-hand side without warning.
If the precision of the result exceeds the defined precision of a receiving variable (and the variable has not been defined for automatic rounding), the result will be truncated on the right-hand side. See the ROUND statement for more information.
Also see the LET statement.
Example:
LENGTH 5.0 ! Declare the length for A, B, C LOCAL A, B, C ! Declare them as LOCAL variables . LET A = 150 ! Set the value for A LET B = 25 ! Set the value for B LET C = A * B ! Multiply A and B, giving C
Division
The backslash (/) is the operator used to perform division on numeric data.
Notes: If the result of a division operation exceeds the defined length of a receiving numeric variable, the value will be truncated on the left-hand side without warning.
If the precision of the result exceeds the defined precision of a receiving variable (and the variable has not been defined for automatic rounding), the result will be truncated on the right-hand side. See the ROUND statement for more information.
Also see the LET statement.
Example:
LENGTH 5.0 ! Declare the length for A, B, C LOCAL A, B, C ! Declare them as LOCAL variables . LET A = 150 ! Set the value for A LET B = 25 ! Set the value for B LET C = A / B ! Divide A by B, giving C
Modulo
The MOD operator performs a modulo operation on the two numeric values (i.e., it divides the first value by the second value and returns the remainder).
The MOD operator is supported in Comet 504 and greater. In Comet32 you may use either MOD or % as the operator.
The syntax is:
numeric-value-1 MOD numeric-value-2 Example:
LET C = 10 MOD 3
This operation returns a value of 1 as 10 divided by 3 equals 3 with a remainder of 1.
Precedence
In a numeric expression containing multiple operations, the multiplication and division operations are performed first (from left to right). Next, the addition and subtraction operations are performed (also from left to right).
This algebraic order can be overridden with parentheses. In a numeric expression containing parentheses, operations inside the parentheses will be performed first, followed by the algebraic order previously described. Parentheses may be nested to any level in a numeric expression -- they will be performed from the inside to the outside.
Results
The temporary result of a numeric operation will contain only as many digits to the right of the decimal point as the most precise operand in the expression. For example, if an expression contains operand with two digits of precision and four digits of precision, the temporary result will contain four digits of precision.
String Operation (Concatenation)
The Internet Basic language supports the string operation of concatenation. The plus sign (+) is used to indicate concatenation (the combining of strings). For example, concatenating two string variables would look like this:
FIRSTNAME$ + LASTNAME$
You may concatenate string constants, string variables, and string functions. Here is an example of concatenating constants with variables:
"(" + AREACODE$ + ")" + PHONENUMBER$
The maximum number of characters in a string is 254. If a concatenation operation results in more characters than have been declared for a receiving variable, characters will be truncated on the right-hand side. THIS TRUNCATION WILL OCCUR WITHOUT WARNING OF ANY KIND.
Relational Operation (IF/THEN/ELSE)
The Internet Basic language supports relational operations in IF/THEN statements.
The following operations are supported:
Operation | Internet Basic syntax |
---|---|
Equal to | EQ or = |
Not equal to | NE or NOT= |
Greater than | GT or > |
Greater than or equal to | GE or >= |
Less than | LT or < |
Less than or equal to | LE or <= |
Contains | Contains |
Soundslike | Soundslike |
Two strings are considered to be equal only when they are identical and have the same current length (number of characters).
When comparing string values, the ASCII values for the characters are compared. For example, upper case "A" is less than lower case "a" because the ASCII value for "A" (65) is less than the ASCII value for "a" (97). See ASCII chart [1]
The Contains operator will be true when the left hand string operand contains the right hand string operand.
The Soundslike operator will be true when the soundex key of both operands are equal. See [2]
Both the Contains and Soundslike operators are case insensitive.
Logical Operations
The Internet Basic language supports the AND and OR logical operations to be used in conjunction with relational expressions. The AND operator tests whether both relational conditions are true, while the OR operator tests for truth of either relational condition. For example:
IF A=B AND B=C THEN... ! Both conditions must be true IF A=B OR B=C THEN... ! Either condition may be true
If AND and OR are combined in a relational expression, the AND operator takes precedence (i.e., it will be evaluated first). It is possible to override this precedence with parentheses, just like the precedence in numeric operations can be overridden.
For more information on relational operations and logical operations, see the IF statement.
Beginning with Comet 2004, logical operations are also supported on binary expressions. The AND, OR, and XOR operators are available.
The AND operator performs a logical conjunction on two expressions. AND compares identically positioned bits in two numeric expressions and sets the corresponding bit in the result field. A result bit will only be set to 1 if both of the corresponding bits in the expression fields are 1. Otherwise the result bit will be 0. For example:
C = A AND B If A = 1010 (binary) and B = 0011 (binary), then C = 0010 (binary).
The OR operator performs a logical disjunction on two numeric expressions. OR compares identically positioned bits in two numeric expressions and sets the corresponding bit in the result field. A result bit will always be set to 1 unless the corresponding bits in both expression fields are 0. For example:
C = A OR B If A = 1010 (binary) and B = 0011 (binary), then C = 1011 (binary).
The XOR operator performs a logical exclusion on two numeric expressions. XOR compares identically positioned bits in two numeric expressions and sets the corresponding bit in the result field. A result bit will only be set to 1 if exactly one of the expression fields has a 1 bit set in the corresponding position. For example:
C = A XOR B If A = 1010 (binary) and B = 0011 (binary), then C = 1001 (binary).