bir hata oluştuğunda kendi kodu çalıştırmak, böylece On Error Goto
kullanarak hata işleyicileri gerekir. (BTW VB6 onlar hataları değil istisnalar denir.) Ücretsiz bir araç MZTools mükemmel - otomatik olarak geçerli rutin adını içerir On Error Goto
ve bir hata işleyicisi ekleyebilir.
Ayrıca, hata ayrıntılarını bir dosyaya kaydeden genel bir rutine de ihtiyacınız vardır; Sağlık uyarısı - Bunu test etmeden yazdım (air code).
Sub MySub()
On Error Goto ErrHandler
'... Do something ...'
On Error Goto 0
Exit Sub
ErrHandler:
Call LogError("MySub", Err, Error$) ' passes name of current routine '
End Sub
' General routine for logging errors '
Sub LogError(ProcName$, ErrNum&, ErrorMsg$)
On Error Goto ErrHandler
Dim nUnit As Integer
nUnit = FreeFile
' This assumes write access to the directory containing the program '
' You will need to choose another directory if this is not possible '
Open App.Path & App.ExeName & ".log" For Append As nUnit
Print #nUnit, "Error in " & ProcName
Print #nUnit, " " & ErrNum & ", " & ErrorMsg
Print #nUnit, " " & Format$(Now)
Print #nUnit
Close nUnit
Exit Sub
ErrHandler:
'Failed to write log for some reason.'
'Show MsgBox so error does not go unreported '
MsgBox "Error in " & ProcName & vbNewLine & _
ErrNum & ", " & ErrorMsg
End Sub
Bonus öneri: roll your own stack trace.
Bonus öneri 2: here den IsInIDE
işlevini kullanarak, bu If Not IsInIDE() Then On Error Goto Handler
gibi bir şeyle IDE hata işleyicileri kapatmak
http://articles.techrepublic.com.com/5100-10878_11-5798663.html O istediğin gibi görünüyor. – johnnyArt
Teşekkürler MarkJ. :) – Royson