|
-
Oct 10th, 2003, 12:20 AM
#1
Thread Starter
Hyperactive Member
trap line no.
hi friends,
Is it possible to track the line no. where the error has occured dynamically.
in the error handler i write to a log file stating the error and the module where the error was occured, i would like to add the line no. also, is it possible....
thanks
-
Oct 10th, 2003, 12:57 AM
#2
I don't think so since after a program is compiled, line numbers have little meaning.
-
Oct 10th, 2003, 02:11 AM
#3
Fanatic Member
-
Oct 10th, 2003, 04:03 AM
#4
Actually I would recommend MZTools ( www.mztools.com )
It allows you to add line numbers to an entire project at the click of a button (or just a single module, or function).
When you have line numbers, in your error handler code you can just look at ERL to find the line where the error occured, eg:
VB Code:
Msgbox "Error occured!" & vbcr & vbcr _
& "Number: " & err.number & vbcr _
& "Decription: " & err.description & vbcr _
& "At line: " & erl
it saves hours of hunting for the bugs - any bug fixing I do now is around 10-20 times faster than it was before I used line numbers
-
Oct 10th, 2003, 10:24 AM
#5
I use MZTools and I never realized that you could do that
-
Oct 10th, 2003, 11:30 AM
#6
Oh Marty, how could you!
actually, the author of MZTools doesn't use it either
-
Oct 10th, 2003, 01:11 PM
#7
-
Oct 19th, 2003, 09:23 PM
#8
Lively Member
Error log and Tracking
Awesome is right!!
this is cool, i just downloaded and tested it...
but tell me does the mztools add numbers to all procedures automatically or can you add line numbers to a given procedure?
i.e does it increment the line numbers per procedure or does it
increment them only in a procedure i.e
some sub
10
20
30
etx
or global
10
20
30
40
etc?
????
with respect
bindu
-
Oct 19th, 2003, 09:25 PM
#9
Re: Error log and Tracking
Originally posted by binduau
Awesome is right!!
this is cool, i just downloaded and tested it...
but tell me does the mztools add numbers to all procedures automatically or can you add line numbers to a given procedure?
i.e does it increment the line numbers per procedure or does it
increment them only in a procedure i.e
some sub
10
20
30
etx
or global
10
20
30
40
etc?
????
with respect
bindu
Try it and let us know.
-
Oct 20th, 2003, 12:24 AM
#10
Lively Member
re mztools...
It works great...
oops i fogot to add an example of the output from the writeError routine
here it is
"ModuleName","FrmEmailConfig"
"Procedure Name","CmdGetEmailData_MouseDown"
"Error Number",170
"Line Number","-2147467259"
"Error Text","Method 'To' of object 'MailItem' failed"
"DefEmailAddress","[email protected]"
"DefEmailSubject","InfoGen Order"
"AutoReplyTemplate","C:\WebEmailorderDB\vbproject\reporttemplate.htm"
"AutoReplySubject","InfoGen Order Confirmation"
"DefEmailTemplate","C:\WebEmailorderDB\vbproject\defaulttpl.tpl"
"DefOutLookOrderFolder","Orders"
"DefProcessFolder","Orders_Processing"
"DefRepeatFolder","Reordered"
"DefoutlookFileProcessFolder","Orders"
"DefOutPutFolder","C:\WebEmailorderDB\vbproject\orderfiles"
"DefFileViewer","D:\TextPad\TextPad.exe"
"DefSMTPServerAddress","mail.upnaway.com"
"DefServerPort","10"
"DefServerTimeout","5"
"DefRetAddress","[email protected]"
"GlbStrReplyHeader",""
"GlbStrReplyFooter",""
"OnTopSetting",0
"LogOnOffSetting",1
"GlbStrLogFileName","C:\WebEmailorderDB\vbproject\newlog.alg"
"
it adds line numbers only to the current procedure...
how to add error logging....
well
It's a bit convoluted, but it is ok..
first
Download MZTOOLS
then .... install it with VB closed..
open your project
open the proc you want to add error logging for..
if it has a header and footer for error checking already you will have to muck around with the proc until the following works..
1. Add a header and footer by clicking on the Add both Button
(to find out which button that is move your mouse across the MZtools Toolbar until you see the popup for it)
2. Look at the following example of an empty proc
(your proc will of course have stuff in it)
VB Code:
Private Sub CmdGetEmailData_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error GoTo CmdGetEmailData_MouseDown_Error
Exit_EmailData_MouseDown:
Exit Sub
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure CmdGetEmailData_MouseDown of Form FrmEmailConfig"
'writeto the error log if logging is turned on
WriteError Err.Number, Erl, Err.Description, "FrmEmailConfig", "CmdGetEmailData_MouseDown"
Resume Exit_EmailData_MouseDown
Then add Line numbers to the proc by clicking on button with lines and numbers on it.
(to remove the line numbers click the button beside it)
Add the following to module..
VB Code:
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
'writeto the error log if logging is turned on
If LogOnOffSetting = 1 Then ' i have a checkbox in my options form for this setting
Dim logFile
logFile = FreeFile
Open GlbStrLogFileName For Append As logFile 'a global log filename
'write error details to logfile
Write #logFile, "Your App 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$
'these are my app settings you can substitute
'yours
'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 Err.Description
Exit Sub
End Sub
hope it works for you

bindu
Last edited by binduau; Oct 20th, 2003 at 12:34 AM.
-
Oct 20th, 2003, 04:01 AM
#11
it adds line numbers only to the current procedure...
Not true I'm afraid - there are three methods of doing it. 
1) - Current Procedure (line numbers unique per proc)
When in the proc, clicking the button with lines and numbers on it.
(to remove the line numbers from a proc, click the button beside that one)
2) - Single File (line numbers unique per proc - why?)
In the Project Explorer window, right click on the file and select "Add line numbers"
3) - Entire Project (line numbers unique across the whole project)
erm.. haven't got MZTools with me as I'm in someone elses office, I think it's the same as a single file (but right-click on the project file).
-
Oct 20th, 2003, 09:27 AM
#12
Lively Member
Oh Ok i stand corrected Re: Line NUmbers
Originally posted by si_the_geek
Not true I'm afraid - there are three methods of doing it. 
1) - Current Procedure (line numbers unique per proc)
When in the proc, clicking the button with lines and numbers on it.
(to remove the line numbers from a proc, click the button beside that one)
2) - Single File (line numbers unique per proc - why?)
In the Project Explorer window, right click on the file and select "Add line numbers"
3) - Entire Project (line numbers unique across the whole project)
erm.. haven't got MZTools with me as I'm in someone elses office, I think it's the same as a single file (but right-click on the project file).
The process of creating an Error log remains the same tho..
with respect

bindu
-
Oct 20th, 2003, 09:31 AM
#13
Lively Member
RE: MZtools
Oh yeh, i forgot to mention how AWESOME mztools are.. i just installed it 5 hours ago and have already saved myself 20 hours
on writing the tech doc i used the xml genreator instead
FABULOUS!!!
bindu
-
Oct 20th, 2003, 09:46 AM
#14
Re: RE: MZtools
Originally posted by binduau
Oh yeh, i forgot to mention how AWESOME mztools are.. i just installed it 5 hours ago and have already saved myself 20 hours
on writing the tech doc i used the xml genreator instead
FABULOUS!!!
bindu
Yeah it's fantastic... by the way, you forgot to mention that you can set up the error handler to whatever you want (then add it to any sub with a single button press).
I have it set up something like this: (items like <this> are inserted automatically by MZ - and there are many more available )
VB Code:
On Error Goto ErrorHandler:
< procedure body (remains as it was) >
ErrorHandler: 'Standard Error Handler
If Err <> 0 Then
Select Case My_Error_Handler(Err, <module name> , < function name > , < Project Name >)
Case "Resume": Resume
Case "Resume Next" : Resume Next
End Select
End If 'End of sub. code:
'(close recordsets, reset mouse pointer, etc., here)
where My_Error_Handler is a Function in a module, and has all my error handling code in (including logging etc).
-
Oct 22nd, 2003, 06:23 PM
#15
Fanatic Member
wow this MZtools is everything i ever dreamed of, and more!
so a big BUMP to this thread for every1 out there
-
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
-
Oct 23rd, 2003, 04:17 AM
#17
good stuff Bindu!
it's similar to what I have developed over the last few years - but with one difference: I don't trust users any more to tell me the important stuff!
I show a similar message to yours, but rather than Err.Description I use a special module to convert it to something that is more meaningful to non-programmers, and save this info (and any extra info that is relevant) to a log file, and send a copy of the info by email (using any available method - SQL Server/Outlook etc).
I also have a retry button (a some errors are time limited, or something that can be fixed by the user), and if apt an ignore button.
ooh, just in time! I haven't got any error emails since my job moved temporarily, but one has just arrived, so heres some sample output (@ is used to mask the sensitive stuff!):
Code:
** Message to user -
(18456)
Login failed for user '@@@@'.
ERL=11880
Database :
Time of sending : 23/10/2003 09:59:26
Source procedure : @@@@@@@ Editor - Login
(Exit=E&xit,Username = @@@)
Procedure variables:
EXE path\name : @@@@@@@ Editor
EXE date or version : 01/10/2003 10:27:16
User logged in : @@@
Error number : 3146
** Last SQL -
** MS Office info:
Excel: Excel.Application.9
Word: Word.Application.9
Outlook: Outlook.Application.9
Access: Access.Application.9
** Mapped Drives:
...
** ODBC (USER DSN's):
...
(SYSTEM DSN's)
...
(Drivers):
...
** Application Registry Settings - HKEY_CURRENT_USER\Software\@@@\@@@@ Editor
\@@@@@
As you can see, I put lots of information in by default (most of my programs use databases and/or MS Office), and I have a "Procedure variables" section, so each procedure can specify more info if appropriate.
Anyway! I hope that this helps anyone who is planning to implement an error handling strategy.
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
|