• Aucun résultat trouvé

the listing to start at the line number and continue to the [_J

Dans le document Publishing is (Page 104-108)

94

i

u

The BASIC Program

end of the program. Using LIST with a dash followed by a line number causes the listing to start at the first line in the program and continue to the specified line number.

• The RUN command usually starts executing a program at the first line. To start execution at a line other than the first, that line number must be specified after the keyword RUN.

A line number range may not be used with this command.

Program Storage and Retrieval

Programs can get to be very long. While it is convenient to be able to execute the whole program just by typing RUN, it is not so convenient if you have to type in a program every time you want to use it. As soon as you type NEW or turn the computer off, the program is gone for good. Since you will often want to change from one program to another, or turn the computer off, it is important that you be able to store pro grams on floppy disk or cassette tape. These are two examples of storage media used to keep permanent copies of programs.

Once a program has been stored on tape or disk, you can turn the computer off or use a different program, and retrieve your stored program anytime you want to use it.

The two commands used to store and retrieve programs are SAVE and LOAD.

First we will see how to SAVE a program to tape or disk.

Type NEW, enter the following program, and RUN it so you are satisfied that it works correctly. Then follow one of the procedures described below, depending on whether you are using tape or disk.

Poem

Please read the article called "Automatic Proofreader," Appen dix I, before typing in any of the programs in this book. Do not type in the rem statement at the end of the program lines.

For example, do not type :rem 240 from line 10.

10

"BY EDWARD CHU" : PRINT

"A SMALL SILVER BOX"

"WITH MOUTHS FLAMING RED,"

"SITS ON MY SHELF"

"DEVOURING BREAD." : PRINT

"I FED HIM SOME SLICES"

"TWO AT A TIME,"

"AND HE HANDS THEM BACK."

"BLACK."

The BASIC Program

If you are storing programs on cassette tape, here is the procedure to use:

1. Rewind the tape to the beginning by pressing the REWIND key on the Datassette. Press STOP when the tape is rewound completely.

2. Type the command SAVE "POEM7' and press I

RETURN. "~

3. The computer will respond with the message PRESS RECORD & PLAY ON TAPE. This is your cue to simulta neously press the RECORD and PLAY keys on your

Datassette. On some models of the Datassette, the PLAY key will automatically be pressed when you press RECORD.

4. As soon as you press RECORD and PLAY on the Datassette, the computer will print the message OK, followed by the message SAVING POEM. You will not be able to see these messages, however, because the screen background color will be changed to match the border color. This is called screen blanking.

5. The tape will start to move. During this time the com puter is taking a copy of the program in memory and storing it on the tape.

6. When the computer is done, it will print the READY prompt, and restore the screen.

7. The tape will have stopped moving, and you can press STOP on the Datassette.

Here is the equivalent procedure for using a disk drive.

1. Insert a properly formatted disk into the disk drive.

Read the disk drive user's manual for instructions on how to format a disk.

2. Type the command SAVE "POEM",8 and press RETURN. The number 8 is called a device number. If you do not type the device number, the computer will try to save the

program on tape. [j

3. The computer will print the message SAVING POEM.

4. The disk drive will be activated, and the computer will

take a copy of the program currently in memory and store it [J on the disk.

5. Upon completion of the SAVE operation, the computer will print the READY prompt, and the disk drive will automat ically stop.

Remember that the SAVE command only stores a copy of

U

96

U

i i

n

The BASIC Program

the program on the tape or disk. The program is still in mem ory after you use the SAVE command, as can be verified by entering the command LIST.

Now you have a copy of the program safely stored on tape or disk for future reference. At this point you are free to type NEW, or even turn the computer off. If you are using disk, be sure to remove your disk from the drive before you turn your computer off.

To retrieve the program, use the LOAD command. Again, this procedure differs slightly for tape and disk.

If you are using cassette tape, follow these steps:

1. Rewind the tape back to the beginning.

2. Type the command LOAD "POEM" and press RETURN.

3. The computer will respond with the message PRESS PLAY ON TAPE. Be sure to press only the PLAY button this time. Do not press RECORD.

The computer will then print the messages OK and SEARCHING FOR POEM on the screen, but you won't be able to see them because once again the screen will be blanked.

5. The tape will start moving as the computer searches for the program.

6. When the computer finds the program, it will stop the tape, print the message FOUND POEM, and restore the screen so you can see the message.

7. After about ten seconds, the computer will print the message LOADING. (On some 64s, you must first press the key labeled with the Commodore logo.) The screen will be blanked again, and the tape will start to move, as the com puter copies the program from tape into memory.

8. When the program is done loading, the READY prompt will be printed, the screen will be restored, and the tape will stop moving. You may want to press the STOP key on the Datassette.

Here are the steps for loading a program on disk.

1. Type the command LOAD "POEM",8 and press RETURN.

2. The computer will print the message SEARCHING FOR POEM.

3. The disk drive will be activated. When the program has

u

The BASIC Program M

been found, the computer will print LOADING.

LJ

4. The disk drive will stop, the READY prompt will be

printed, and the program will be in memory. [J

To see that the program is indeed back in memory, use *"""'

the commands LIST or RUN. Every line of the program

should be back, exactly as it was saved. Once a program has ! | been saved, it can be loaded again and again.

There is one other thing you should be aware of concern ing the LOAD command. When you load a program from tape or disk, it replaces the one currently in memory. Enter the fol lowing lines.

NEW

18 PRINT "USE A MICROWAVE INSTEAD"

Now continue with the appropriate loading procedure.

Once the program has been loaded, you will see that line 18 no longer exists. Always be careful that you do not inadver tently erase a program in memory by loading a new one.

This brings up another important topic: storing multiple programs on tape or disk. To store a second program on a tape, start the tape at the position where it stopped when you saved the first program. Type the SAVE command again, but this time use a different filename. When programs are stored on tape or disk, they are called files. The character string after the SAVE command is the name of the file. Filenames can be up to 16 characters long, and they should be chosen so that they describe the program being saved. If the second program saved was the demonstration in the first chapter, a good filename would be DOODLE.

Let's say that you have saved two programs to tape, named POEM and DOODLE, and want to load the second one. Rewind the tape, enter the command LOAD

"DOODLE", and follow the normal loading procedure. The »

Dans le document Publishing is (Page 104-108)