HP Business BASIC/XL Reference Manual - HP 3000 MPE/iX Computer Systems - Edition 1 (32715-90001)

4- 88
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 !!
ON ERROR
The ON ERROR statement defines an error-handling routine to handle all
run-time errors that are not trapped by an ON DBERROR or ON END statement
in the same program.
Syntax
{GOTO }
[{GO TO } ]
ON ERROR [{GOSUB }
line_id
]
[{GO SUB} ]
[CALL
sub-id
]
Parameters
line_id
Line label or line number. Control will transfer to
this
line_id
when the ON ERROR statement executes.
sub_id
Subunit identifier. Control will transfer to this
subunit when the ON ERROR statement executes.
Table 4-8 shows the similarities and differences between the three forms
of the ON ERROR statement.