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 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, 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 table statements allow manipulation of stored data from within a user's programs. (See Chapter 15, Data Table Statements for information on the Sheerpower data table statements.)
Sheerpower stores data in tables (also sometimes known as structures. Tables look something like this:
Example 4-8 Data Table |
---|
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 table 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 tables and defining fields, see Chapter 16, Database Setup. |
The field data in tables can be referenced by using table references. To reference a field, indicate the table name and the expression of the field whose contents you want to access:
table_name(field_expr) |
table_name is the name associated with the table. field_expr is the name of a field in the table. When a field is referenced, Sheerpower searches the current record for this field and reads its contents. Some examples of table 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 that the following characters are an expression, not the field name. If the pound sign is not included, 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) |
Example 4-9 Multiple Occurrence Fields |
---|
open table cust: name 'sheerpower:samples\customer', access input extract table cust print cust(address#1) print cust(address#2) end extract end 10010 Sunset Cliffs Blvd. 9988 HIBERT STREET SUITE 310 1122 Monroe Ave. PO Box 8765 11A SE. Hwy A1A PO Box 11A-A 2111 Brawley Blvd. 987 Shadow Oaks Lane 123 Dry Gully PO Box 1 6655 Cirrus Skyway PO Box 60000 11 Lower Medicine Hat Rd. 32 Nybble Ct. PO Box 64 112 Pipes Peak Point PO Box 221 999 World Vista Avenue #2 Bougainvillea Blvd. |
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-10 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-11 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.
Previous | Next | Contents | Index |