| Previous | Contents | Index |
Boolean variables represent either a TRUE or FALSE condition. These variables can be expressed with a trailing "?". For example:
| Example 4-4 BOOLEAN variables |
|---|
done? = FALSE
do
input 'Ready': ans$
if _exit then done? = true
if _back then done? = true
loop until done?
end
Ready? exit
|
Expressions can be:
A constant is a value that does not change during a program execution. Constants can be any of the three data types: integer numeric, real numeric or string.
Integer numeric constants are written with digits, with no decimal fraction. An integer constant can end with a percent sign. Examples:
235 412%
|
Real numeric constants are written with a sign, digits, and a decimal point. For example, 5.38 is a real numeric constant.
String constants must be enclosed in quotes. The quotes are called string delimiters. They tell SheerPower where the string begins and ends. The quotes are not considered part of the string. Everything within the quotes is considered part of the string. Note that the following strings are different:
| Example 4-5 String constants and delimiters |
|---|
print 'Account number (##-####)'
print ' Account number (##-####)'
end
Account number (##-####)
Account number (##-####)
|
An empty string is called a null string. A null string is indicated by a pair of quotes with nothing between them ("").
String delimiters can be single quotes (') or double quotes ("). However, the quotes must match and be paired.
Quotes can be included as part of a string by using them within the string delimiters. For example:
"Message'Time to go home!'"
|
The string part of this is:
Message 'Time to go home!'
|
The delimiter quotes can be used within a string by repeating them twice. For instance:
"Message ""Time to go home!"""
|
The string part of this is:
Message "Time to go home!"
|
Variables are a way of storing values that can change in the program during execution. A variable names a storage location. The value of the variable is stored in this location. Here are two types of variables:
Two other constructs are used in ways similar to variables---you can use them in expressions and assign values to them:
Variables are represented by a name consisting of a letter or series of letters, numbers and underscore characters. Variables:
Some examples of valid variables are:
TODAY$ X%
Z INDEX
|
The following are examples of string variables:
TODAY$ X$
LAST_NAME$ ANSWER$
|
The following are examples of real numeric variables:
INDEX Z
COUNTER AMOUNT
|
SheerPower uses the last assigned value when a variable is referenced. See Section 5.7, Private Variables in Routines, for more information on using variables.
An array is a variable that consists of a group of elements. Each element represents a storage location. A different value can be assigned to each element. Here is an example of an array:
QUANTITY(1)
QUANTITY(2)
QUANTITY(3)
QUANTITY(4)
QUANTITY(5)
|
To indicate which element to access, use numbers after the array name, called subscripts. The subscripts are enclosed in parentheses. Example: amount(3,2)
Subscripts must be given as integers. If a real numeric subscript is given, it will be rounded and the integer portion used. Arrays can contain real numeric, integer or string values. String and integer arrays are designated by placing the appropriate symbols after the array name and before the subscript. For example:
a$(5,10) a%(5,10)
|
About arrays:
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:
| Previous | Next | Contents | Index |