In this chapter, you will learn how to load and run programs written in BASIC.
A file is a collection of information accessed by a single name. A volume is a collection of files. (For an introductory explanation of volumes and files, see the "Mass Storage Concepts" chapter of this manual.) This section shows how to locate and specify BASIC files.
Use CAT to determine the names of the files on a volume:
CAT [Return]
If you do not specify a volume, the default volume will be assumed. You should get a listing similar to the following figure:
:CS80,700
VOLUME LABEL: B9836
FILE NAME PRO | TYPE | REC/FILE | BYTE/REC | ADDRESS |
MyProg | PROG | 14 | 256 | 16 |
VisiComp | ASCII | 29 | 256 | 30 |
GRAPH | BIN | 171 | 256 | 59 |
GRAPHX | BIN | 108 | 256 | 230 |
CAT normally directs its output to the current PRINTER IS device (the default is the CRT display). CAT can also direct the catalog to a specified device, as shown in the following examples:
CAT TO #701 send output to printer at address 701
CAT TO #Device_selector
The parameter following the # is known as a device selector and is further described in the, "Using a Printer," chapter, HP BASIC 6.2 Programming Guide, and in the Glossary of the HP BASIC 6.2 Language Reference.
To specify a file on the default volume, merely use its name as shown in the following examples:
LOAD "MY_PROG"
GET "PROG_ASCII"
PURGE "A_FILE"
PURGE "A*" WILDCARDS enabled
If the file is not on the default volume or not in the current working directory (if using a hierarchical directory), then you will need to do one of the following things:
LOAD "MY_PROG:,700"
LOAD "M*:,700" WILDCARDS enabled
MASS STORAGE IS "/USERS/MARK"
LOAD "MY_PROG"
MASS STORAGE IS ":,700"
LOAD "MY_PROG"
Files can be uniquely identified by specifying the following information:
Here is a syntax drawing of the components of a file specifier:
(Hierarchical Directories Only)
If you want to specify a file, but it is not in the current working directory, then you must include this information in the file specifier.
The following figure represents a directory structure that will be used in this section's examples. None of the examples change the default volume; all remain in the directory structure of the current default volume. See the next section for examples about changing the current default volume.
The following statements access files in directories of the current volume:
CAT "/" Catalogs files in the root directory
LOAD "/ROOT_PROG" Loads ROOT_PROG from the root directory
CAT "/USERS" Catalogs USERS, listing MARK, JOHN, and KEITH
which gives you a list of the files MARK, JOHN, and KEITH. To load the file PROG_3 from the directory named JOHN (subordinate to the directory named USERS in the root):
LOAD "/USERS/JOHN/PROG_3" Loads PROG_3 from directory JOHN
CAT ".." Catalogs directory which is superior to current working directory
For example, if MARK is the current directory, this command would catalog USERS, located above MARK in the preceding directory structure.
If the file is not on the default volume, then you must include the volume specifier. The volume specifier is the information on the label which you should have affixed to each of your mass storage volumes during installation. For help, see the chapter "Verifying and Labeling Peripherals" in Installing and Maintaining HP BASIC/WS 6.2.
Here is a typical hardware configuration:
The following statements specify volume units 0 and 1 connected to the computer through the HP-IB interface at select code 7, with primary address 0:
LOAD "MY_PROG:CS80,700,1" Loads program from flexible disk drive
LOAD "MY_PROG:,700,1"
CAT ":,700" Catalogs the hard disk (implied volume unit 0)
The following statements set the default mass storage to an HP 9133 drive at interface select code 7 with primary address 0; unit number 1 specifies the flexible-disk drive:
MASS STORAGE IS ":CS80,700,1"
MSI ":,700,1"
If the volume has a hierarchical directory structure (HFS volumes), then you may also specify a current working directory:
MSI "/USERS/MARK:CS80,700,1"
MSI "/USERS/MARK:,700,1"
MSI "/USERS/MARK" If the default volume is :,700,1
This section gives you a brief overview of loading and running BASIC programs. To load and then run a program, follow this procedure:
CAT [Return]
LOAD filename Use LOAD for program file type PROG
GET filename Use GET for program file type ASCII or HP-UX
The entries under TYPE in this catalog listing show which command to use:
:CS80,700
VOLUME LABEL: B9836
FILE NAME PRO | TYPE | REC/FILE | BYTE/REC | ADDRESS |
MY_PROG | PROG | 14 | 256 | 16 |
VISI_TOOL | ASCII | 29 | 256 | 30 |
GRAPH | BIN | 171 | 256 | 59 |
GRAPHX | BIN | 108 | 256 | 230 |
LOAD "MY_PROG" Program MY_PROG is type PROG
GET "VISI_TOOL" Program VISI_TOOL is type ASCII
For a file located on a disk not in the default drive, a volume specifier would be required. For example, if after labeling the disks following the procedures in "Verifying and Labeling Peripherals" in Installing and Maintaining HP BASIC/WS 6.2, we had a PROG file named OUR_PROG on a disk with volume specifier CS80,700,1, here is the statement to load the file:
LOAD "OUR_PROG:,700,1"
4. To run the program you just loaded, type:
RUN [Return]
On HP 98203 keyboards, you can also use [RUN]. On ITF keyboards, [f3] in the System menu, and User 1 and 2 menus serve the same purpose. If key labels are not currently displayed, then execute KEY LABELS ON or press [Menu] to turn them on.
NOTE |
---|
Note Some software is secured against being run without proper authorization
which is usually accomplished by the software requiring a special codeword
that is somehow related to:
If the program prompts you to enter a codeword, you will need to get it from the software vendor. |
There are two statements used in BASIC for retrieving programs from mass storage:
These statements can be executed from the keyboard as commands or included in a program. When executed as commands, they are used to bring a program into the computer's memory so it can be edited or run. When included within a program, they are used to link together the segments of large programs.
The LOAD command brings in programs from a PROG file, with the option of beginning program execution at a specified line. It clears any existing program from the computer's memory before loading a new file. For example:
LOAD "CANNON" Loads program into memory without running it
LOAD "CANNON",10 Loads program into memory and starts running it from line 10
LOAD "CANNON",Here Loads program into memory and starts running it from line labeled Here
If specifying a line label or number, it must identify a line in the main program segment (not in a subprogram or user-defined function). See the "Program Structure and Flow" chapter of the HP BASIC 6.2 Programming Guide for further information.
The LOAD command cannot be used to bring in arbitrary program segments or append to a main program like GET can. Subprogram segments can be appended using LOADSUB, as described in the "Subprograms" chapter of the HP BASIC 6.2 Programming Guide.
The GET command brings in programs or program segments from an ASCII or HP-UX file, with the options of appending them to an existing program and/or beginning program execution at a specified line.
To clear any existing program from the computer's memory and load an ASCII or HP-UX file, simply use GET followed by the file name. For example, the following statement clears any BASIC program currently in memory, and loads an ASCII or HP-UX file called FORMULA assuming the file contains valid program lines.
GET "FORMULA"
If the first line does not start with a valid line number, the GET is not performed and error 68 (syntax error during GET) is reported.
Assuming the file contains valid program lines that were placed in the file by a SAVE operation, and their line numbers are still valid after any renumbering that is specified, the lines will be entered into program memory. If there is a syntax error in any of the program lines in the file, the lines in error are turned into comments, error 68 is reported, and the syntax error message is sent to the system printer. This might happen if the program was written and saved on a computer that had a version of BASIC different from the one being used for the GET operation. This may also happen when a "language extension" binary is required for using the keyword, but the binary is not currently loaded into memory.
GET can also specify that program execution is to begin. This is done by adding two line identifiers:
For example, assume there is no program in memory and an ASCII file named RATES contains valid program lines. A typical command to bring the contents of this file into memory and begin execution at line 10 is:
GET "RATES",100,10
If there is already a program in memory, an append and run is allowed. For example:
GET "RATES",250,100
specifies that any existing lines from 250 to the end of the program in memory are to be deleted, the contents of file RATES are to be renumbered and appended to the program in memory beginning at line 250. Program execution begins at line 100. Although any combination of line identifiers is allowed, the line specified as the start of execution must be in the main program segment (not in a SUB or user-defined function). Execution will not begin if there was an error during the GET operation. For further information about this use of GET, see the "Program Structure and Flow" chapter in the HP BASIC 6.2 Programming Guide.
Do one of the following to run a program:
You can include a line identifier in a RUN command to indicate where program execution is to begin. For example,
RUN 200 Begin execution at line number 200
RUN Line_id Begin execution at the line label
BASIC automatically performs a prerun when you execute RUN or press [RUN]. Prerun completes the following tasks:
When a program is running, the keyboard is still active. Commands can be executed, variables can be inspected and changed, and the state of the computer can be changed. ==Live keyboard== means commands can be executed during a running program. A principal use for live keyboard commands is troubleshooting and debugging programs, as discussed in the "Debugging Programs" chapter of the HP BASIC 6.2 Programming Guide. See "Introduction to the System" in this manual for tables showing how to pause, stop, and continue a program.
To demonstrate some of the interaction between a program and the keyboard, enter the following simple program.
10 DISP "Next command?"
20 X=0
30 PRINT X;
40 X=X=1
50 WAIT .1
60 GOTO 30
70 END
Error 122: Program not continuable
The program runs again, but the number sequence has restarted from the beginning, not from the next number in the sequence. RUN causes the program to restart, not resume.