IBM Lotus Symphony


On Error GoTo ...Resume 语句 [运行时]

发生错误后启用错误处理例程,或恢复程序执行。

语法:

On {Error GoTo Labelname | GoTo 0 | Resume Next}

参数:

GoTo Labelname:当发生错误时,使错误处理例程跳转到“Labelname”行处开始执行。

Resume Next:当发生错误时,程序继续执行出错语句后面的语句。

GoTo 0:在当前过程中禁用错误处理程序。

On Error GoTo 语句用于处理宏中发生的错误。该语句必须插入到过程(位于本地错误处理例程中)或模块的开始位置。

示例:

Sub ExampleReset

On Error Goto ErrorHandler

Dim iNumber As Integer

Dim iCount As Integer

Dim sLine As String

Dim aFile As String

aFile = "c:\data.txt"

iNumber = Freefile

Open aFile For Output As #iNumber

Print #iNumber, "This is a line of text"

Close #iNumber

iNumber = Freefile

Open aFile For Input As iNumber

For iCount = 1 to 5

Line Input #iNumber, sLine

If sLine <>"" then

rem

end if

Next iCount

Close #iNumber

Exit Sub

ErrorHandler:

重置

MsgBox "All files will be closed",0,"Error"

End Sub


产品反馈 | 其他文档 | 商标