|
-
Oct 22nd, 2003, 09:30 PM
#16
Lively Member
Update to Adding error logging
Originally posted by SkiNLaB
wow this MZtools is everything i ever dreamed of, and more!
so a big BUMP to this thread for every1 out there
Here is an error handler I Set up in the mztoolz options dialog
i use it with the function to write errors to the logfile (See below)
If you add the header and footer to every new function before
you begin coding in it then you will have automatic error logging setup in one click of the button..
However you should change the error logfile location to your parameters. I have a global variable (GlbStrLogFileName ) which
is stored in the registry set to ......
"C:\WebEmailorderDB\vbproject\newlog.alg"
YOu can name your file what ever you want.
i have a setup panel in my proggies options dialog which looks like this.....

1. Click on the button at the end of the mztoolbar
2. Choose error handler and delete what is in the window then
paste in the following
Start copy below
VB Code:
On Error GoTo {PROCEDURE_NAME}_Error
{PROCEDURE_BODY}
Exit_{PROCEDURE_NAME}:
Exit {PROCEDURE_TYPE}
{PROCEDURE_NAME}_Error:
MsgBox _
"Error " & Err.Number & " (" & Err.Description & ") has occured " _
& vbCrLf & "in the {PROCEDURE_NAME} procedure of {MODULE_TYPE} {MODULE_NAME}" _
& vbCrLf & " in the interests of making the program bug free" _
, vbExclamation, "Please Write Down This Error Message!"
WriteError Err.Number, Erl, Err.Description, "{MODULE_NAME} {MODULE_TYPE}", "{PROCEDURE_NAME}"
resume Exit_{PROCEDURE_NAME}
end copy
An example of how to use/call the error logging
function "WriteError"
VB Code:
'---------------------------------------------------------------------------------------
' Procedure : mnuSend_Click
' DateTime : 10/20/2003 12:07
' Author : Steve
' Purpose : Displays a test email
'---------------------------------------------------------------------------------------
Private Sub mnuSend_Click()
'These must be initialized before anything else is tested or
'errors will result.
Dim appOL As Outlook.Application
Dim NewEmail As Outlook.MailItem
10 On Error GoTo mnuSend_Click_Error
20 Screen.MousePointer = vbHourglass
' The following code reads a text file and uses that for the body of the email
' It then sends an email as an Outlook MailItem
'I deliberately didn't include the TextFileToString_FX file
'function in this post.
' Instantiate the Outlook and Mail Item objects
' You will need a reference to Outlook 9 or 10 libraries.
30 Set appOL = Outlook.Application
40 Set NewEmail = appOL.CreateItem(olMailItem)
50 With NewEmail
60 .To = DefEmailAddress
'default address if any
'default subject
70 .Subject = DefEmailSubject
' Now open a text file and reads its contents for inclusion in the email
'uses default reply template
80 .Body = TextFileToString_FX(DefEmailTemplate)
' Display the email so you can ammend details and add your email address.
90 .Display
100 Set NewEmail = Nothing
110 Set appOL = Nothing
120 Screen.MousePointer = vbDefault
130 End With
Exit_mnuSend_Click:
140 Exit Sub
mnuSend_Click_Error:
150 MsgBox _
"Error " & Err.Number & " (" & Err.Description & ") has occured " _
& vbCrLf & "in the mnuSend_Click procedure of Form FrmEmailConfig" _
& vbCrLf & " in the interests of making the program bug free" _
, vbExclamation, "Please Write Down This Error Message!"
160 WriteError Err.Number, Erl, Err.Description, "FrmEmailConfig Form", "mnuSend_Click"
170 Resume Exit_mnuSend_Click
End Sub
See the post below for the output
Paste the following to a Module..
VB Code:
'---------------------------------------------------------------------------------------
' Procedure : WriteError
' DateTime : 10/20/2003 12:34
' Author : Steve
' Purpose : Send The Error Variables to the log file which will be defined in
' GlbStrLogFileName
'---------------------------------------------------------------------------------------
Sub WriteError(LineNum As String, _
errorNum As Integer, _
ErrDesc As String, _
moduleName As String, _
procName As String)
Dim intVarLen%, strVariable$, I%, aChr As String * 1
On Error GoTo Err_WriteError
If LogOnOffSetting = 1 Then
Dim logFile
logFile = FreeFile
Open GlbStrLogFileName For Append As logFile
'write error details to logfile
Write #logFile, "If you are reading this file and there are recorded errors in it"
Write #logFile, "It does not necessarily mean that the program has bugs in it."
Write #logFile, vbCrLf
Write #logFile, "The interpretation of this file should be left to Core-Software Support"
Write #logFile, "or click on the button marked Send Error Log to Support."
Write #logFile, "on the Error Logging Tab in the Options Dialog."
Write #logFile, "--------------------------------------------------------------"
Write #logFile, "CoreSoft Web-Mail AutoProcessor Error Log Details Follow"
Write #logFile, "--------------------------------------------------------------"
Write #logFile, "ModuleName", moduleName$
Write #logFile, "Procedure Name", procName$
Write #logFile, "Error Number", errorNum%
Write #logFile, "Line Number", LineNum$
Write #logFile, "Error Text", ErrDesc$
'write App State to logfile
Write #logFile, "DefEmailAddress", DefEmailAddress
Write #logFile, "DefEmailSubject", DefEmailSubject
Write #logFile, "AutoReplyTemplate", AutoReplyTemplate
Write #logFile, "AutoReplySubject", AutoReplySubject
Write #logFile, "DefEmailTemplate", DefEmailTemplate
Write #logFile, "DefOutLookOrderFolder", DefOutLookOrderFolder
Write #logFile, "DefProcessFolder", DefProcessFolder
Write #logFile, "DefRepeatFolder", DefRepeatFolder
Write #logFile, "DefoutlookFileProcessFolder", DefoutlookFileProcessFolder
Write #logFile, "DefOutPutFolder", DefOutPutFolder
Write #logFile, "DefFileViewer", DefFileViewer
Write #logFile, "DefSMTPServerAddress", DefSMTPServerAddress
Write #logFile, "DefServerPort", DefServerPort
Write #logFile, "DefServerTimeout", DefServerTimeout
Write #logFile, "DefRetAddress", DefRetAddress
Write #logFile, "GlbStrReplyHeader", GlbStrReplyHeader
Write #logFile, "GlbStrReplyFooter", GlbStrReplyFooter
Write #logFile, "OnTopSetting", OnTopSetting
Write #logFile, "LogOnOffSetting", LogOnOffSetting
Write #logFile, "GlbStrLogFileName", GlbStrLogFileName
Write #logFile, "--------------------------------------------------------------------------------------"
Close logFile
End If
Exit Sub
Err_WriteError:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in the EmailErrLog procedure of Module ErrBas", vbExclamation, "Please Write down this message"
Exit Sub
End Sub
have fun
bindu
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|