Commodore 128 Programmer's Reference Manual page 387

Hide thumbs Also See for 128:
Table of Contents

Advertisement

n
INPUT/OUTPUT GUIDE
377
I \
opens file number 111 on device number 8, using channel 12. The file is opened to
default drive 0, with the filename "NAME," as a sequential file. The W specifies that a
write operation will take place. To store data, it is "written" on the disk. Data is
retrieved by "reading" the disk.
Enter, save and run the following programs as sample routines to create, save and
read a sequential file. See your disk drive manual for more information.
10
REM STORE DATA
11
REM NOTE PROGRAM STOPS WHEN YOU RESPOND WITH "END".
20
OPEN 5,8,5,"EXAMPLE,S,W"
25
DO
30
INPUT * 'NAME OF A FRIEND'' ;N$
40
PRINT#5,N$
50
IF N$ =' 'END' 'THEN CLOSE 5:END
60
LOOP
n
I i
NOTE: In C128 mode, the Commodore 128 has a set of disk input/
output commands. These include the DLOAD and DSAVE commands
already described, as well as the DOPEN, DCLOSE and other com
mands. See the BASIC 7.0 Encyclopedia in Chapter 2 or your disk drive
manual for details on any of these commands.
I \
Line 20 tells the disk drive to open a sequential file for writing data. Line 30
obtains the information from the keyboard by requesting it on the screen. The PRINT#
statement in line 40 specifies the file number where the information is to be written.
Line 40 is the statement that actually writes the data to the channel and creates the
contents of the file. Line 50 also puts a recognizable end-of-file marker—the word
"end" at the end of the file. Line 50 closes the file after all data has been written.
Here's a program that reads the data from the sequential file you just created:
10
20
25
30
40
<
50
60
REM RETRIEVE FILES
OPEN 6,8,6,"EXAMPLE,S,R"
DO
INPUT#6,L$
IF L$ = "END'THEN CLOSE6:END
PRINT L$
LOOP
Line 20 opens a channel to the sequential file called EXAMPLE for reading. Once
the end item is found, the file is properly closed. As each item is retrieved using the
INPUT# statement, it is printed to the screen with a simple PRINT statement. Any
sequential file in which all writing has been completed and which is already closed can
be opened only as a read file; it cannot be written to unless an APPEND operation is
specified or the @ prefix is used.
Files can be expanded in size with the BASIC 7.0 APPEND command as follows:

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents