|
This example creates a file, puts the numbers 1-10 in it, then attempts to {Get} past the end of the file. The {On Error} statement traps the error and execution goes to the Debugger code which uses {Reset} to close the file before exiting.
Sub main
' Put the numbers 1-10 into a file
Dim x as Integer
Dim y as Integer
On Error Goto Debugger
Open "C:\TEMP001" as #1 Len=2
For x=1 to 10
Put #1,x, x
Next x
Close #1
msgtext="The contents of the file is:" & Chr(10)
Open "C:\TEMP001" as #1 Len=2
For x=1 to 10
Get #1,x, y
msgtext=msgtext & Chr(10) & y
Next x
MsgBox msgtext
done:
Close #1
Kill "C:\TEMP001"
Exit Sub
Debugger:
MsgBox "Error " & Err & " occurred. Closing open file."
Reset
Resume done
End Sub
上面这段代码我总是运行不到Debugger标签这里,因为Get语句没有超出文件的最后啊,可是最上面的那段英文(书上copy来的)却说这个例子会企图超出文件的最后而出错,跳转到Debugger标签啊。怎么回事呢?
另外,Reset的到底实现了什么功能呢?
烦请哪位解答,谢谢了! |
|