VB icon

Error Logger

Email
Submitted on: 1/19/2015 4:15:00 PM
By: Hagbard (from psc cd)  
Level: Intermediate
User Rating: By 2 Users
Compatibility: VB 5.0
Views: 831
 
     This is the code I use to keep a track of errors throughout the program. It comes in useful for keeping track of the errors I haven't weeded out in the initial testing.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Error Logger
' Description:This is the code I use to keep a track of errors throughout the program. It comes in useful for keeping track of the errors I haven't weeded out in the initial testing.
' By: Hagbard (from psc cd)
'
' Inputs:erDesc - Error Description
erNum - Error Number
subname - Sub Name where error originates
'
' Returns:Appends the error log file with the error description,number, Sub name and Date/Time
'**************************************

'Declare a Public constant ErrorLog filename and a Application Name
Public Const conErrorLogFile = "errorlog.txt"
Public const conAppname = "ApplicationName"
'The Sub for writing to the error log file
'Send Variables by value :
'erDesc = Error Description
'erNum = Error Number
'subName = name of procedure where error originated
Public Sub UpdateErrorLog(ByVal erDesc, ByVal erNum, ByVal subName As String)
On Error GoTo handleel
Dim strErrorLogname As String	'Full pathname for error log
Dim strAF As String		'Path to Application folder
strAF = App.Path
'check for root path
If Right(strAF, 1) = "\" Then
strAF = strAF
Else
strAF = strAF & "\"
End If
'get the full pathname from the app folder and the constant error log name
strErrorLogname = strAF & conErrorLogFile
'open the error log file for appending - file is created if it doesn't already exist
Open strErrorLogname For Append As #23 ' Open file for input.
'write the line to the file
'writes error description, error number, Sub name, Date/Time
Write #23, erDesc, erNum, subName, Now
'Close the file
Close #23' Close file.
ExitEL:
Exit Sub
handleel:
MsgBox Err.Description & vbCrLf & Err.Number, , conAppName & " - Error Writing Log"
Resume ExitEL
End Sub
'in the error handler for each sub I added the line to call the UpdateErrorLog procedure
'eg in the Form_load procedure
Private Sub Form_load()
On error goto HandleFormLoaderr1
'form_load code
'do whatever has to be done
exitloader:
Exit Sub
HandleformLoaderr1:
'Give the user a message
MsgBox Err.Description & vbCrLf & Err.Number, , conAppName & " - Error"
'Send the error info to the sub
UpdateErrorLog Err.Description, Err.Number, "Form_Load"
Resume exitloader
End Sub


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.