| Previous | Contents | Index |
PRINT CL(LAST)
/
the field is specified by its field name
|
If the field is specified as an expression, the expression will need to be preceded by a pound sign (#). The pound sign tells SheerPower that the following characters are an expression, not the field name. If the pound sign is not included, SheerPower will interpret the characters as a field name. Here are two examples:
PRINT CL(#FIELDNAME$)
/
the field is specified by the variable FIELDNAME$
PRINT CL(#FIELDNUM)
/
the field is specified by the variable FIELDNUM
|
See Section 15.8.1.1, FIELD Expressions for an example of a program that uses field
expressions.
4.7 Multiple Occurrence Fields
Fields with multiple occurrences (single dimension array) are supported.
When defining a field with multiple occurrences, the length of the field must be the length of a single occurrence.
Each occurrence of a field is accessed by including the occurrence number in the field expression. For example, to access the second occurrance of the field "address":
print cust(address#2) |
Compound expressions can be used in programs. Compound expressions consist of operators and operands. There are three types of compound expressions:
Numeric expressions consist of numeric (integer or real) variables, constants or expressions separated by arithmetic operators. The arithmetic operators are +, -, *, /, and ^.
Constants Variables
+ Add
4%+2% Z + TWO16
- Subtract
4%-2% Z - TWO16
/ Divide
4%/2% Z / TWO16
* Multiply
4%*2% Z * TWO16
^ Raise to a power
4%^2% Z ^ TWO16
|
Any number of these operators can be combined in an expression.
4 + Z ^ TWO16 Z * TWO16 / 2
|
Generally, two arithmetic operators cannot be used next to each other. However, a + or - sign can be used to indicate a positive or negative number. For example:
total * -2 = total * (-2)
total / +2 = total / (+2)
|
If all the values in an arithmetic expression are of the same data type, the result of the expression will be of that data type. For example, if an expression consists only of integer numbers, it will yield an integer result. If an expression consists only of real numbers, the result will be a real number. If an expression consists of integers and real numbers, the result will be a real number. If the target of a real calculation is an integer (a% = 1.5 + 2.8), the result is rounded before it is assigned to the target.
String expressions are strings concatenated (joined). String expressions can be joined by a plus sign (+) or by an ampersand (&). SheerPower evaluates this type of string expression by concatenating the strings. For example:
| Example 4-9 String expressions |
|---|
z$ = 'MO' + 'TH' & 'ER' print z$ end MOTHER |
In the above example, SheerPower joins the strings separated by a plus sign and an ampersand, and assigns their value to z$. String constants, variables, functions, etc. can be included in your expressions. For example:
| Example 4-10 String expression with string variable |
|---|
let last$ = ' is it.' print 'This' + last$ end This is it. |
Conditional expressions are expressions which yield a TRUE (1) or FALSE (0) value. Conditional expressions are created by using either relational or logical operators. When SheerPower evaluates a conditional expression, it returns a value of either TRUE or FALSE. If the expression is TRUE, SheerPower returns the integer 1. If the expression is FALSE, SheerPower returns the integer 0.
Relational operators are similar to those used in algebra. The relational operators are:
= equals X=Y X is equal to Y
< less than X<Y X is less than Y
> greater than X>Y X is greater than Y
<= less than or equal to X<=Y X is less than or equal
to Y
>= greater than or equal to X>=Y X is greater than or
equal to Y
<> not equal to X<>Y X is not equal to Y
|
X and Y can be any unconditional or conditional expression.
When relational operations are performed on strings, SheerPower determines which string occurs first in the ASCII collating sequence and returns TRUE or FALSE. For instance, when you perform relational operations on two strings, SheerPower checks the ASCII values for each character in each string. SheerPower compares the strings character by character using these ASCII values, and determines where there is a difference in the values.
When SheerPower finds a character that differs, it compares the two and determines which one has a smaller ASCII code number. SheerPower then returns a TRUE or FALSE value depending on the relational expression. For example:
| Example 4-11 Performing relational operations on strings |
|---|
a$ = 'TEXT' b$ = 'TEST' MESSAGE$ = 'Strings are equal' if a$ < b$ then message$ = a$ + ' is less than ' + b$ if b$ < a$ then message$ = b$ + ' is less than ' + a$ print message$ end TEST is less than TEXT |
SheerPower compares the two strings. They are identical up to the third character. The ASCII value of S is 53. The ASCII value of X is 58. Therefore SheerPower prints "TEST is less than TEXT".
The logical operators are:
NOT NOT X TRUE if X is false and
FALSE if X is true.
AND X AND Y TRUE if X and Y are true.
OR X OR Y TRUE if X or Y is true.
XOR X XOR Y TRUE if X is true, or if Y is true but
FALSE if both X and Y are true.
EQV X EQV Y TRUE if X and Y are true, or
TRUE if X and Y are false,
but FALSE otherwise.
IMP X IMP Y TRUE if X is true and Y is false.
|
X and Y can be any expressions. Logical operators are usually used on integers or expressions which yield an integer result such as conditional expressions. Logical operators will always yield an integer result. If a logical operator is used on a real number, the real number is rounded and the resulting integer is used.
Logical expressions always return an integer value. If the integer value is a 1, the expression is TRUE. If the integer value is a 0, the expression is FALSE. (NOT 0 is equal to -1 and is TRUE. NOT 1 is equal to -2 and is FALSE.)
VALUE TRUE FALSE
+--------------------------+
| 0 | | X |
|-----------|------|-------|
| 1 | X | |
|-----------|------|-------|
| NOT 0 (-1)| X | |
|-----------|------|-------|
| NOT 1 (-2)| | X |
+--------------------------+
|
Logical operators can be used to do bit manipulation. Computers represent values in a binary code, using ones and zeros. SheerPower integer values are represented as a 32-bit binary longword. A bit which is set to 1 is considered on. A bit which is set to 0 is off. The value of the word is equal to the value of all the bits which are on, added together. For example:
0 0 0 1 0 1 1 1 = 16 + 4 + 2 + 1 = 23
|
The last bit has a value of 1. The second to the last bit has a value of 2. The third bit has a value of 4, the fourth a value of 8, the fifth bit has a value of 16, and so on. Each bit has a value double that of the previous one:
0 0 0 0 0 0 0 0
---------------------------------------------
128 64 32 16 8 4 2 1
|
Bits can be manipulated and tested using logical operators. The logical operators work on bits. They compare each position in each word according to the particular rules of the logical operator. For instance, here is the AND operator used on two values:
| Example 4-12 Bit manipulation |
|---|
let a% = 23% // 00010111 let b% = 37% // 00100101 let c% = (a% and b%) print c% end 5 |
When SheerPower executes this program, it compares the two values. It sets a bit in the result to 1 (on) only if both the bits at a given position are on (1). The value of the resultant word is 5:
A% 0 0 0 1 0 1 1 1 = 23
B% 0 0 1 0 0 1 0 1 = 37
---------------
C% 0 0 0 0 0 1 0 1 = 5
|
| Previous | Next | Contents | Index |