Results 1 to 17 of 17

Thread: trap line no.

  1. #1

    Thread Starter
    Hyperactive Member ravi15481's Avatar
    Join Date
    Aug 2002
    Location
    INDIA
    Posts
    421

    Thumbs up 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
    A good friend...

  2. #2

  3. #3
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721
    I read somewhere on this forum that this was possible using an additional tool called AXtools...

    Do a Search!!

    HTH
    ** HOLLY **

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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:
    1. Msgbox "Error occured!" & vbcr & vbcr _
    2.           & "Number: " & err.number & vbcr _
    3.           & "Decription: " & err.description & vbcr _
    4.           & "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

  5. #5

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    Oh Marty, how could you!

    actually, the author of MZTools doesn't use it either

  7. #7
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    This is off the topic, but I gota say, I just installed MZTOOLS and this thing is awsome!!!

    I ran the statistics and Code Review and found some areas to do it "better" already. Not to mention the ability to creat things like headders with the click of a mouse!


    This is one cool tool!


    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  8. #8
    Lively Member binduau's Avatar
    Join Date
    Sep 2003
    Location
    Perth Australia
    Posts
    121

    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


  9. #9
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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.

  10. #10
    Lively Member binduau's Avatar
    Join Date
    Sep 2003
    Location
    Perth Australia
    Posts
    121

    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:
    1. Private Sub CmdGetEmailData_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.  
    3. On Error GoTo CmdGetEmailData_MouseDown_Error
    4.  
    5.  
    6.  
    7. Exit_EmailData_MouseDown:
    8.  Exit Sub
    9.  
    10. MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure CmdGetEmailData_MouseDown of Form FrmEmailConfig"
    11. 'writeto the error log if logging is turned on
    12. WriteError Err.Number, Erl, Err.Description, "FrmEmailConfig", "CmdGetEmailData_MouseDown"
    13. 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:
    1. Sub WriteError(LineNum As String, _
    2. errorNum As Integer, _
    3. ErrDesc As String, _
    4. moduleName As String, _
    5. procName As String)
    6.        
    7.        Dim intVarLen%, strVariable$, I%, aChr As String * 1
    8.         On Error GoTo Err_WriteError
    9.  
    10.  'writeto the error log if logging is turned on          
    11.             If LogOnOffSetting = 1 Then ' i have a checkbox in my options form for this setting
    12.                 Dim logFile
    13.                 logFile = FreeFile
    14.                
    15.                 Open GlbStrLogFileName For Append As logFile 'a global log filename
    16.                     'write error details to logfile
    17.                      Write #logFile, "Your App Error Log Details Follow"
    18.                      Write #logFile, "--------------------------------------------------------------"
    19.                      Write #logFile, "ModuleName", moduleName$
    20.                      Write #logFile, "Procedure Name", procName$
    21.                      Write #logFile, "Error Number", errorNum%
    22.                      Write #logFile, "Line Number", LineNum$
    23.                      Write #logFile, "Error Text", ErrDesc$
    24.                  
    25.                       'these are my app settings you can substitute
    26.                       'yours
    27.                     'write App State to logfile
    28.                     Write #logFile, "DefEmailAddress", DefEmailAddress
    29.                     Write #logFile, "DefEmailSubject", DefEmailSubject
    30.                     Write #logFile, "AutoReplyTemplate", AutoReplyTemplate
    31.                     Write #logFile, "AutoReplySubject", AutoReplySubject
    32.                     Write #logFile, "DefEmailTemplate", DefEmailTemplate
    33.                     Write #logFile, "DefOutLookOrderFolder", DefOutLookOrderFolder
    34.                     Write #logFile, "DefProcessFolder", DefProcessFolder
    35.                     Write #logFile, "DefRepeatFolder", DefRepeatFolder
    36.                     Write #logFile, "DefoutlookFileProcessFolder", DefoutlookFileProcessFolder
    37.                     Write #logFile, "DefOutPutFolder", DefOutPutFolder
    38.                     Write #logFile, "DefFileViewer", DefFileViewer
    39.                     Write #logFile, "DefSMTPServerAddress", DefSMTPServerAddress
    40.                     Write #logFile, "DefServerPort", DefServerPort
    41.                     Write #logFile, "DefServerTimeout", DefServerTimeout
    42.                     Write #logFile, "DefRetAddress", DefRetAddress
    43.                     Write #logFile, "GlbStrReplyHeader", GlbStrReplyHeader
    44.                     Write #logFile, "GlbStrReplyFooter", GlbStrReplyFooter
    45.                     Write #logFile, "OnTopSetting", OnTopSetting
    46.                     Write #logFile, "LogOnOffSetting", LogOnOffSetting
    47.                     Write #logFile, "GlbStrLogFileName", GlbStrLogFileName
    48.                                
    49.                     Write #logFile, "--------------------------------------------------------------------------------------"
    50.  
    51.                 Close logFile
    52.             End If
    53.  
    54. Exit Sub
    55. Err_WriteError:
    56.     MsgBox Err.Description
    57.     Exit Sub
    58. End Sub


    hope it works for you



    bindu
    Last edited by binduau; Oct 20th, 2003 at 12:34 AM.

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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).

  12. #12
    Lively Member binduau's Avatar
    Join Date
    Sep 2003
    Location
    Perth Australia
    Posts
    121

    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

  13. #13
    Lively Member binduau's Avatar
    Join Date
    Sep 2003
    Location
    Perth Australia
    Posts
    121

    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

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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:
    1. On Error Goto ErrorHandler:
    2.  
    3. < procedure body (remains as it was) >
    4.  
    5. ErrorHandler:                      'Standard Error Handler
    6.    If Err <> 0 Then
    7.       Select Case My_Error_Handler(Err,  <module name> , < function name > , < Project Name >)
    8.       Case "Resume":          Resume
    9.       Case "Resume Next" : Resume Next
    10.       End Select
    11.    End If                               'End of sub. code:
    12.    '(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).

  15. #15
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    wow this MZtools is everything i ever dreamed of, and more!

    so a big BUMP to this thread for every1 out there

  16. #16
    Lively Member binduau's Avatar
    Join Date
    Sep 2003
    Location
    Perth Australia
    Posts
    121

    Lightbulb 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:
    1. On Error GoTo {PROCEDURE_NAME}_Error
    2.  
    3.     {PROCEDURE_BODY}
    4. Exit_{PROCEDURE_NAME}:
    5.  
    6.    Exit {PROCEDURE_TYPE}
    7.  
    8. {PROCEDURE_NAME}_Error:
    9.  
    10.    MsgBox _
    11.         "Error " & Err.Number & " (" & Err.Description & ") has occured " _
    12.         & vbCrLf & "in the {PROCEDURE_NAME} procedure of {MODULE_TYPE} {MODULE_NAME}" _
    13.         & vbCrLf & " in the interests of making the program bug free" _
    14.         & " Please Email Software support at [email][email protected][/email]" _
    15.         , vbExclamation, "Please Write Down This Error Message!"
    16.  WriteError Err.Number, Erl, Err.Description, "{MODULE_NAME} {MODULE_TYPE}", "{PROCEDURE_NAME}"
    17.  
    18. resume Exit_{PROCEDURE_NAME}
    end copy


    An example of how to use/call the error logging
    function "WriteError"

    VB Code:
    1. '---------------------------------------------------------------------------------------
    2. ' Procedure : mnuSend_Click
    3. ' DateTime  : 10/20/2003 12:07
    4. ' Author    : Steve
    5. ' Purpose   : Displays a test email
    6. '---------------------------------------------------------------------------------------
    7. Private Sub mnuSend_Click()
    8.        'These must be initialized before anything else is tested or
    9.              'errors will result.
    10.        Dim appOL As Outlook.Application
    11.        Dim NewEmail As Outlook.MailItem
    12. 10       On Error GoTo mnuSend_Click_Error
    13.  
    14. 20     Screen.MousePointer = vbHourglass
    15.          
    16.               ' The following code reads a text file and uses that for the body of the email
    17.               ' It then sends an email as an Outlook MailItem
    18.              
    19.            'I deliberately didn't include the TextFileToString_FX file
    20.             'function in this post.
    21.              
    22.               ' Instantiate the Outlook and Mail Item objects
    23.               ' You will need a reference to Outlook 9 or 10 libraries.
    24.              
    25. 30            Set appOL = Outlook.Application
    26. 40            Set NewEmail = appOL.CreateItem(olMailItem)
    27. 50            With NewEmail
    28.              
    29. 60            .To = DefEmailAddress
    30.               'default address if any
    31.              
    32.               'default subject
    33. 70            .Subject = DefEmailSubject
    34.              
    35.               ' Now open a text file and reads its contents for inclusion in the email
    36.              
    37.               'uses default reply template
    38. 80            .Body = TextFileToString_FX(DefEmailTemplate)
    39.              
    40.               ' Display the email so you can ammend details and add your email address.
    41.              
    42. 90            .Display
    43.              
    44.              
    45. 100           Set NewEmail = Nothing
    46. 110           Set appOL = Nothing
    47. 120   Screen.MousePointer = vbDefault
    48. 130           End With
    49. Exit_mnuSend_Click:
    50.  
    51. 140      Exit Sub
    52.  
    53. mnuSend_Click_Error:
    54.  
    55. 150      MsgBox _
    56.               "Error " & Err.Number & " (" & Err.Description & ") has occured " _
    57.               & vbCrLf & "in the mnuSend_Click procedure of Form FrmEmailConfig" _
    58.               & vbCrLf & " in the interests of making the program bug free" _
    59.               & " Please Email Software support at [email][email protected][/email]" _
    60.               , vbExclamation, "Please Write Down This Error Message!"
    61. 160    WriteError Err.Number, Erl, Err.Description, "FrmEmailConfig Form", "mnuSend_Click"
    62.  
    63. 170   Resume Exit_mnuSend_Click
    64. End Sub



    See the post below for the output


    Paste the following to a Module..


    VB Code:
    1. '---------------------------------------------------------------------------------------
    2. ' Procedure : WriteError
    3. ' DateTime  : 10/20/2003 12:34
    4. ' Author    : Steve
    5. ' Purpose   : Send The Error Variables to the log file which will be defined in
    6.             ' GlbStrLogFileName
    7. '---------------------------------------------------------------------------------------
    8. Sub WriteError(LineNum As String, _
    9. errorNum As Integer, _
    10. ErrDesc As String, _
    11. moduleName As String, _
    12. procName As String)
    13.        Dim intVarLen%, strVariable$, I%, aChr As String * 1
    14.         On Error GoTo Err_WriteError
    15.  
    16.             If LogOnOffSetting = 1 Then
    17.                 Dim logFile
    18.                 logFile = FreeFile
    19.                
    20.                 Open GlbStrLogFileName For Append As logFile
    21.                     'write error details to logfile
    22.                      Write #logFile, "If you are reading this file and there are recorded errors in it"
    23.                      Write #logFile, "It does not necessarily mean that the program has bugs in it."
    24.                      Write #logFile, vbCrLf
    25.                      Write #logFile, "The interpretation of this file should be left to Core-Software Support"
    26.                      Write #logFile, "Email this file to [email][email protected][/email] for help."
    27.                      Write #logFile, "or click on the button marked Send Error Log to Support."
    28.                      Write #logFile, "on the Error Logging Tab in the Options Dialog."
    29.                      Write #logFile, "--------------------------------------------------------------"
    30.  
    31.                      Write #logFile, "CoreSoft Web-Mail AutoProcessor Error Log Details Follow"
    32.                      Write #logFile, "--------------------------------------------------------------"
    33.                      Write #logFile, "ModuleName", moduleName$
    34.                      Write #logFile, "Procedure Name", procName$
    35.                      Write #logFile, "Error Number", errorNum%
    36.                      Write #logFile, "Line Number", LineNum$
    37.                      Write #logFile, "Error Text", ErrDesc$
    38.                  
    39.  
    40.                     'write App State to logfile
    41.                     Write #logFile, "DefEmailAddress", DefEmailAddress
    42.                     Write #logFile, "DefEmailSubject", DefEmailSubject
    43.                     Write #logFile, "AutoReplyTemplate", AutoReplyTemplate
    44.                     Write #logFile, "AutoReplySubject", AutoReplySubject
    45.                     Write #logFile, "DefEmailTemplate", DefEmailTemplate
    46.                     Write #logFile, "DefOutLookOrderFolder", DefOutLookOrderFolder
    47.                     Write #logFile, "DefProcessFolder", DefProcessFolder
    48.                     Write #logFile, "DefRepeatFolder", DefRepeatFolder
    49.                     Write #logFile, "DefoutlookFileProcessFolder", DefoutlookFileProcessFolder
    50.                     Write #logFile, "DefOutPutFolder", DefOutPutFolder
    51.                     Write #logFile, "DefFileViewer", DefFileViewer
    52.                     Write #logFile, "DefSMTPServerAddress", DefSMTPServerAddress
    53.                     Write #logFile, "DefServerPort", DefServerPort
    54.                     Write #logFile, "DefServerTimeout", DefServerTimeout
    55.                     Write #logFile, "DefRetAddress", DefRetAddress
    56.                     Write #logFile, "GlbStrReplyHeader", GlbStrReplyHeader
    57.                     Write #logFile, "GlbStrReplyFooter", GlbStrReplyFooter
    58.                     Write #logFile, "OnTopSetting", OnTopSetting
    59.                     Write #logFile, "LogOnOffSetting", LogOnOffSetting
    60.                     Write #logFile, "GlbStrLogFileName", GlbStrLogFileName
    61.                                
    62.                     Write #logFile, "--------------------------------------------------------------------------------------"
    63.  
    64.                 Close logFile
    65.             End If
    66.  
    67. Exit Sub
    68. Err_WriteError:
    69.     MsgBox "Error " & Err.Number & " (" & Err.Description & ") in the EmailErrLog procedure of Module ErrBas", vbExclamation, "Please Write down this message"
    70.     Exit Sub
    71. End Sub



    have fun


    bindu



  17. #17
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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
  •  



Click Here to Expand Forum to Full Width