HP 3000 Manuals

ON END [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation


HP Business BASIC/XL Reference Manual

ON END 

The ON END statement traps the end-of-file condition for a specified
file.  That is, if an end-of-file is encountered during an I/O operation,
the ON END statement causes an interrupt.  When HP Business BASIC/XL
responds to the interrupt, it transfers control to the line, subroutine,
or subprogram specified by the ON END statement.

The OFF END statement disables the ON END statement.  If an end-of-file
is encountered during an I/O operation, and no ON END statement is
associated with it (or its ON END statement is disabled), an error
occurs.  An active ON ERROR statement can trap this error.  See the ON
ERROR statement for more information.

Syntax 

             {GOTO  }
            {{GO TO }        }
ON END #fnum{{GOSUB } line_id}
            {{GO SUB}        }
            {CALL sub_id     }

Parameters 

fnum             The file number of the file that the ON END statement
                 applies to.

line_id          Line label or line number.  Control will transfer to
                 this line_id when the ON END statement executes.

sub_id           Subunit identifier.  Control transfers to this subunit
                 when the ON END statement executes.

Examples 

The following example uses the ON END statement to trap an end-of-file
error.  Lines 20-90 set up the file.  Line 200 contains the ON END
statement.  Lines 210-240 read the file, and an end-of-file occurs.  The
ON END statement prints line 300, and execution continues.

          10 DIM A(15),B(15)
          20 CREATE "Test1",FILESIZE=15,RECSIZE=10
          30 ASSIGN #1 TO "Test1"
          40 FOR I=1 TO 3
          50    A(I)=I
          60    B(I)=I*2
          70    PRINT #1;A(I),B(I)
          80 NEXT I
          90 POSITION #1;BEGIN
         200 ON END #1 GOTO 300
         210 FOR I=1 TO 15
         220    READ #1;A1,B1
         230    PRINT A1,B1
         240 NEXT I
         250 END
         300 PRINT " End of data file reached !!  "
         310 STOP
     >run
      1                   2
      2                   4
      3                   6
      End of data file reached !!



MPE/iX 5.0 Documentation