Sharp OZ-707 Operation Manual - Page 35
Program 1, Creating a Sequential File, Reading Data from a Sequential File, Program 2, Accessing
UPC - 074000012141
View all Sharp OZ-707 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 35 highlights
Program 1 - Creating a Sequential File 10: DIM DE$(1) 20: OPEN "E:DATA" FOR OUTPUT AS #20 30: CLS 40: INPUT "NAME: ";NA$ 50: IF NA$ = "DONE" THEN 100 60: INPUT "DEPARTMENT: ";DE$(1) 70: INPUT "DATE HIRED: ";HI$ 80: PRINT #20,NA$;",";DE$(1);",";HI$ 90: GOTO 30 100: CLOSE #20 110: END Before execution, enter: INIT "E:10K" IENTER I to allocate storage space in the RAM disk E. RUN NAME: SAMUEL GOLDWYN DEPARTMENT: AUDIONISUAL AIDS DATE HIRED: 01/12172 NAME: MARVIN HARRIS DEPARTMENT: RESEARCH DATE HIRED: 12103/65 NAME: DEXTER HORTON DEPARTMENT: ACCOUNTING DATE HIRED: 04/27/81 NAME: DONE Reading Data from a Sequential File . Now look at Program 2. It accesses the file DATA that was created In Program 1 and displays the name of everyone hired in 1981. Program 2 - Accessing a Sequential File 10: DIM DE$(1) 20: OPEN "E:DATA" FOR INPUT AS #20 30: INPUT #20,NA$,DE$(1 ),HI$ 40: IF RIGHT$(HI$,2)="81" THEN PRINT NA$ 50: GOTO 30 58 RUN DEXTER HORTON Input past end in 30 Program 2 reads, sequentially, every item in the file, and prints the names of employees hired in 1981. When all the data has been read, line 30 causes an ERROR. To avoid this error, use the EOF function, which tests for the end-of-file. The revised program looks like this: 10: DIM DE$(1) 20: OPEN "E:DATA" FOR INPUT AS #21 25: IF EOF(21) THEN 60 30: INPUT #21 ,NA$,DE$(1 ),HI$ 40: IF RIGHT$(HI$,2)="81" THEN PRINT NA$ 50: GOTO 25 60: CLOSE #21 70: END As shown by these programs, the following steps are required to create a sequential file and access the data in it: 1. OPEN the file for OUTPUT. 2. Write data to the file using the PRINT# statement. 3. CLOSE the file and reopen it in INPUT mode to read the data. 4. Use the INPUT# statement to read data from the file into the program. Adding Data to a Sequential File If you have an existing data file and want to add more data to the end of it, you cannot simply open the file in the OUTPUT mode and start writing data. As soon as you open a sequential file in the OUTPUT mode, you destroy its current contents. Instead, use the APPEND mode. If the file does not already exist, the OPEN statement will work exactly as it would if the OUTPUT mode had been specified. The following procedure can be used to add data to an existing file called "FOLKS". 59