8 File Storage

Trapping EOR and EOF Conditions

An error usually results from encountering one of two conditions--a logical or physical EOF during READ# or an EOR during direct READ#. The ON END# statement can detect those errors and cause a branching operation.

In some of the previous programs, for example, ERROR 59 appears after the last item is accessed, telling you that the end of file has been reached. This error message can be avoided by including an ON END# statement in the program.

Here is a modified version of the example program used when "Repositioning the Record Pointer". The program ends when the end of file is reached.

10   CREATE "DATA15",15
20   ASSIGN #1 TO "DATA15"
30   READ #1,8
40   ON END #1 GOTO Exit
50   FOR V=1 TO 50
60   PRINT #1;V
70   NEXT V
80 Exit:  ! end of file found.
100  END
As another example, the next program prints four data items into each record of files DATA.1 and DATA.2. When DATA.1 is filled, reading the EOF mark causes a branch to the subroutine Newfile, which opens file DATA.2 for the rest of the PRINT# routine.

10   CREATE "DATA.1",20
20   CREATE "DATA.2",20
30   ASSIGN #1 TO "DATA.1"
40   ON END #1 GOSUB Newfile
50   FOR R=1 TO 100
60     PRINT #1;R,R^2,R^3,R^4
70   NEXT R
80   STOP
90 Newfile:   !  open new file.
100  ASSIGN #1 TO "DATA.2"
120  END
ON END is disabled during INPUT, LINPUT and EDIT statements. ON END can interrupt ON ERROR and ON KEY routines. ON END cannot be executed from the keyboard.

An ON END is deactivated with the OFF END# statement:

OFF END# file number

NOTE: Under the HP 260 environment the ON END # command could be used with the PRINT # statement to signify when a file was filled. In the HP-UX environment files are dynamic, rather than static, and printing will continue until the entire disk is full if a limit is not written into the program. Therefore, make sure you change any converted HP 260 programs that make use of ON END # and PRINT #, in this way.

Eloquence Language Manual - 19 DEC 2002