| Previous | Contents | Index |
Substrings are a way to refer to a part of a string. The format of a substring is:
str_var [begin : end]
|
str_var is the name of a string variable. begin is the position in the string where your substring begins. end is the position at which the substring ends. For example, here is a string called ALPHABET$:
| Example 4-6 Substrings |
|---|
alphabet$ = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' print alphabet$[9:14] end IJKLMN |
The substring ALPHABET$[9:14] tells SheerPower to begin at the ninth character and count to the 14th character. Everything between and including these two positions makes up the substring. Therefore, the substring is "IJKLMN".
begin and end are integers. If real numbers are given for these positions, SheerPower rounds them and uses the remaining integers. A substring can be manipulated like any other expression, and data can be stored in the substring. Substrings can be used also to change the value of a string. For example:
| Example 4-7 Substrings used to change string value |
|---|
let a$ = 'Your tests are in.' print a$ let a$[6:10] = 'results' print a$ end Your tests are in. Your results are in. |
Another type of variable is a structure reference. SheerPower includes a transparent interface to several record management systems, including the Windows file management system. One of the major features of SheerPower is its ability to perform database operations as a part of the language. SheerPower's data structure statements allow manipulation of stored data from within a user's programs. (See Chapter 15, Data Structure Statements for information on the SheerPower data structure statements.)
SheerPower stores data in structures. Structures look something like this:
| Example 4-8 SheerPower data structure |
|---|
FIELDS
/ | \
/ | \
/ | \
/ | \
/ | \
R | Client | Last name | First name
E | Number | |
C |---------|-----------------------------|--------------------
O _____ |8|0|5|4|3|C|a|s|s| | | | | | | | | | | |C|a|t|h|y| | | | | |
R _____ |8|0|5|4|2|B|r|o|c|k| | | | | | | | | | |B|u|d| | | | | | | |
D | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
S
positions
|
Each structure is made up of records and fields. In the CLIENT structure above, we have a record for each customer.
Each record consists of fields. For example, our customer records might contain a field for the customer's ID number, last name, first name, address, phone number, company name, etc.. Each of these pieces of data is stored in its own field - the name field, address field, phone number field, etc.. These fields appear as columns in the example shown above.
For information on creating structures and defining fields, see Chapter 16, Database Setup. |
The field data in structures can be referenced by using structure references. To reference a field, indicate the structure name and the expression of the field whose contents you want to access:
struc_name(field_expr)
|
struc_name is the name associated with the structure. field_expr is the name of a field in the structure. When a field is referenced, SheerPower searches the current record for this field and reads its contents. Some examples of structure references are:
CLIENT(PHONE) CATALOG(PART_NUM)
|
The field_expr can be either a string or numeric expression.
A string constant can be used to specify the field name. If the field name is given as a string constant, it need not be enclosed in quotes. SheerPower will use the string constant as the field name:
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.
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.
| Previous | Next | Contents | Index |