Loading and Running Programs

In this chapter, you will learn how to load and run programs written in BASIC.

Finding and Specifying Files

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.

Cataloging 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 PROTYPE REC/FILEBYTE/RECADDRESS
MyProgPROG14 256 16
VisiComp ASCII29 256 30
GRAPH BIN 171 256 59
GRAPHX BIN108 256230

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.

Specifying a File

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:

Directory, File, and Volume Specifiers

Files can be uniquely identified by specifying the following information:

Here is a syntax drawing of the components of a file specifier:

Files Not in the Current Working Directory

(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.

Files Not on the Default Volume

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)

Changing the Default Volume and Current Working Directory

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

A Brief Look at Loading and Running Programs

This section gives you a brief overview of loading and running BASIC programs. To load and then run a program, follow this procedure:

  1. If the program is on a flexible disk, insert that disk into one of your disk drives. Use the default volume, to avoid having to specify the drive's volume specifier. If the program is on your hard disk, continue with step 2.
  2. Execute CAT to verify your program is on the disk. Include the volume specifier if the disk is not the default volume; for example :,702,1.
    CAT [Return]
    

  3. Load the program into computer memory.
    
        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 PROTYPEREC/FILEBYTE/RECADDRESS
MY_PROGPROG1425616
VISI_TOOLASCII2925630
GRAPHBIN17125659
GRAPHXBIN108256230

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:
  • your machine's serial number (stored in permanent memory)
  • a serial number stored in an optional HP 46084 ID Module

If the program prompts you to enter a codeword, you will need to get it from the software vendor.

A Closer Look at Loading Programs

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.

Using LOAD

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.

Using GET

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.

GET with Automatic Program Clearing

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.

Using GET to Append and Run

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.

A Closer Look at Running Programs

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

Prerun

BASIC automatically performs a prerun when you execute RUN or press [RUN]. Prerun completes the following tasks:

Live Keyboard

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.

Controlling Program Execution

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

  1. After you enter the program, execute RUN and observe the CRT. The DISP message appears in the display line, the printout area fills with a sequence of numbers, and the run light indicates that a program is running.
  2. Press Pause ([Stop] on the ITF keyboard). The printout of numbers stops, and all the data on the CRT remains unchanged. The run light now indicates that the program is paused and can be continued. The program line that appears at the bottom of the CRT is the next line that will be executed when program execution resumes.
  3. Press {{Step}} ([f1]) a few times. The program is executed one line at a time, as indicated by the lines changing at the bottom of the CRT. The program is still paused and continuable after each press of the {{STEP}} key. The {{STEP}} key can be a great help when you are trying to find certain kinds of problems. The "Debugging Programs" chapter in HP BASIC 6.2 Programming Guide gives the details of this and other debugging tools.
  4. Press {{Continue}} ([f2]). The printout on the CRT resumes with the next number in the sequence. The run light again indicates that a program is running.
  5. Press [Shift]-[Stop] (Stop) The printout of numbers stops, and all the data on the CRT remains unchanged. However, the run light is off, indicating a stopped condition.
  6. Press {{Continue}} ([f2]). An error results, because a stopped program cannot be continued.

    Error 122: Program not continuable

  7. Press {{RUN}} ([f3]).

    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.

  8. Type X=1 and press [Return]. Notice that the numbers being printed start over with "1". The live keyboard was used to change the value of "X", and the program used the new value from the keyboard.
  9. Press [Reset]. The program stops and the data remains in the printout area, but the display line is cleared and the message BASIC Reset appears at the bottom of the CRT. Although the clearing of the display line seems like a minor effect, it indicates an important point. Reset and Stop have different effects on interfaces and peripheral devices. This aspect of Reset is summarized in the "Reset Tables" in the "Useful Tables" appendix of the HP BASIC 6.2 Language Reference and is discussed fully in the HP BASIC 6.2 Interface Reference.
  10. Press {{RUN}} ([f3]). Then type WAIT 5 and press [Return]. The run light changes to indicate that a keyboard command is being executed and the printout is delayed for five seconds while the live keyboard command is processed. Actually, the run light changed when the X=1 command was executed in step 8, but it may have happened so fast that you didn't see it.
  11. Press Pause ([Stop]) and then type EDIT and press [Return]. The display on the CRT changes to show the program. The line you were editing last appears in the current-line position. The run light is still visible in the lower right-hand corner and it indicates that the program is paused.
  12. Press {{CONTINUE}} ([f2]). The CRT returns to normal mode, and the printout of numbers continues in sequence. However, the previous data on the display was lost when the CRT was used for EDIT mode.
  13. Press Pause ([Stop]). Then type EDIT 50 and press [Return]. The CRT changes to EDIT mode and the program appears again. This time, line 50 is in the current-line position. Notice that the run light indicates that the program is paused. Change line 50 to WAIT .2 and press [Return]. The new line 50 is entered, but the run light changes. Editing the program caused it to move from the paused state to the stopped state.