Lotus Symphony 1.2


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,"這是一行文字"

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「所有的檔案都會關閉」,0,「錯誤」

End Sub


其他文件 | 商標