| Previous | Contents | Index |
The MEDIA statement allows you to open media files with SheerPower.
Currently the following media files are supported by the MEDIA statement in SheerPower:
The MEDIA statement also has as features/options:
media loop: string_expr$ // play this over and over again |
such as:
| Example 14-31 Playing Media Files in a Loop |
|---|
media loop: '@yes.wav' |
This will continue to play as the program continues execution. This can be used to provide "background music" to an application.
To stop playing looped media:
| Example 14-32 To Stop Playing Looped Media |
|---|
media '' // stop any background media that is playing |
See Section 6.7, File and Structure Access Functions for more on working with files in SheerPower. |
This chapter explains the SheerPower data structure statements. One of the major features of SheerPower is its ability to perform database operations as part of the language. The data structure statements allow you to manipulate data structures in your own programs.
List of Data Structure Statements:
OPEN STRUCTURE
CLOSE STRUCTURE
EXTRACT STRUCTURE
REEXTRACT STRUCTURE
CANCEL EXTRACT
ADD STRUCTURE
DELETE STRUCTURE
INCLUDE
EXCLUDE
SORT
FOR EACH
ASK STRUCTURE
SET STRUCTURE
LOCK STRUCTURE
UNLOCK STRUCTURE
UNLOCK STRUCTURE: COMMIT
UNLOCK ALL: COMMIT
In all data structure statements, the word TABLE can be used interchangeably with STRUCTURE. For example:
OPEN STRUCTURE is the same as OPEN TABLE |
SheerPower's data management system stores data file information in structures. (Chapter 16, Database Setup tells how structures are created.) A structure file contains the following information:
In SheerPower, you address the structure file and not the dataset directly.
A SheerPower structure is made up of records and fields. A structure looks something like this:
| Example 15-1 Data Structure DIAGRAM |
|---|
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
|
In the above example, the records are the horizontal lines of information. In the CLIENT structure above, there is a record for each customer.
Each record consists of fields. For example, the customer records alone 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. The fields appear as columns in the diagram above.
To reference a field, indicate the structure and the desired field. The field name is enclosed in parentheses.
struc_name(field_name)
|
struc_name is the name associated with the structure. field_name is the name of a field in the structure. SheerPower searches for the field specified in the current record and reads its contents.
| Example 15-2 SheerPower structure |
|---|
open structure cl: name 'sheerpower:samples\client'
extract structure cl: key id = '80522'
print cl(last), cl(first) // print last and first
// fields from the CL structure
end extract
close structure cl
end
Errant Earl
|
OPEN STRUCTURE struc_name: NAME 'struc_filename'
[, ACCESS INPUT | OUTIN] [, LOCK] [, DATAFILE filename]
[, OPTIMIZE OFF]
|
| Example 15-3 OPEN STRUCTURE |
|---|
open structure cl: name 'sheerpower:samples\client', &
access input, lock
extract structure cl
include cl(state) = 'CA'
exclude cl(phone)[1:3] = '619'
sort ascending by cl(last)
end extract
print 'List of California clients by last name'
for each cl
print cl(first); ' '; cl(last), cl(phone)
next cl
close structure cl
end
List of California clients by last name
Dale Derringer (818) 223-9014
Earl Errant (408) 844-7676
|
The OPEN STRUCTURE statement is used to open a data structure. The structure must be open in order to reference data in the structure (i.e. change field data, add or delete records). struc_name is a name (i.e. nickname) you assign to the structure. You use this name to refer to the structure within the program. The structure name must be unique within the program or program system. If the structure name is associated with another open structure, an exception is generated. The structure name must meet the requirements for variable names.
After the keyword NAME, is the file specification of the structure file being opened. (See Chapter 16, Database Setup for information on legal structure file names.) The file specification can be any valid string expression.
The ACCESS option tells SheerPower whether to open the structure for input (reading field data) or for input and output (reading, changing and adding field data). ACCESS input is the default open mode for structures, meaning, that if no ACCESS option is provided, SheerPower opens the structure for INPUT.
When SheerPower executes the OPEN statement, it searches for the structure file specified. SheerPower opens the structure and assigns it the structure name. If the structure file does not exist, an exception is generated.
The ACCESS option determines how you can access the structure.
The access options are:
The LOCK option causes SheerPower to lock the structure from write access by others. As long as the structure is open, the structure cannot be modified by others. This can speed up SheerPower's structure statements (EXTRACTs especially). The particular effect depends on the file management system being used.
The DATAFILE option overrides the default datafile as specified by the structure.
DATAFILE file_spec
|
file_spec is the file specification of the data file you want to open. The file_spec can be any string expression.
15.3 CLOSE STRUCTURE struc_name
CLOSE STRUCTURE struc_name
|
| Example 15-4 CLOSE STRUCTURE |
|---|
open structure cl: name 'sheerpower:samples\client'
extract structure cl
include cl(state) = 'CA'
exclude cl(phone)[1:3] = '619'
sort ascending by cl(last)
end extract
print 'List of California Clients'
for each cl
print cl(first); ' '; cl(last), cl(phone)
next cl
close structure cl
end
List of California Clients
Dale Derringer (818) 223-9014
Earl Errant (408) 844-7676
|
CLOSE STRUCTURE closes a structure from further access. Once the structure is closed, you cannot reference records or add them, and you cannot change field data. struc_name is the name associated with the structure, the name assigned with the OPEN statement.
You can use the statement CLOSE ALL to close all open structures and other files.
| Previous | Next | Contents | Index |