Advertisement
C_Volume2 Debugging and Error Handling #73393

ErrorExample.vbp

This is an example of how to use the intrinsic Visual basic App object to log errors to a file, which may later be helpful in debugging an application. The log file has the error number, error description, form name, sub or function name, and a date-time stamp when the error occurred. This also limits the error so that multiple loggings of the same error are not recorded in iterations.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
'* This must be compiled into an executable for the intrinsic 
'* error logging to work
'* It will not work from the development enviroment.
'* paste this code on to a form, save and compile it for the demo 
Private Sub Form_Load()
'*here is an example of a sub which I raise errors in for the demo
 ErrorDemoSub
 
 MsgBox "Errors Recorded in Error Log File"
 
 Unload Me
 
End Sub
Private Sub ErrorDemoSub()
 Dim i As Integer
 Dim ii As Integer
 On Error GoTo MyErrorLog
 'we'll simulate an error in a loop although we only log it one time
 For i = 1 To 20
 For ii = 1 To 5 
  Err.Raise i
 Next ii
 Next i
 
 Exit Sub
 
MyErrorLog:
 LogErrors Err.Number, Err.Description, Me.Name, "ErrorDemoSub"
 Err.Clear
 Resume Next
 
End Sub
Original Comments (3)
Recovered from Wayback Machine