Results 1 to 9 of 9

Thread: Debugging tip

  1. #1

    Thread Starter
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Debugging tip

    This may be old news to many but I had to debug a project that needed to run on a machine with a scanner and did not have Visual Basic on it for me to debug. I added this to the error handler and it helps by giving the line number of the error.

    Use the Erl Function to Debug

    When you’re faced with difficult debugging chores or when you want to enhance the value of error logs produced by production code, line numbers can help determine exactly where errors are occurring. The Erl function, not documented since VB3, pinpoints the problem. Here’s an example of how Erl returns the line number of an error:


    Public Sub DivideByZero()
    On Error GoTo HandleError
    10 Dim x As Long
    20 Dim y As Long
    30 y = 5
    40 MsgBox y / x 'error
    Exit Sub
    HandleError:
    Debug.Print "Error on line " & Erl
    End Sub

    There is a free tool called MZTools that has a lot of nice features and one is to automatically assign line numbers to a project. Using that and Erl helps debugging exes.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    all I know is if I used line numbers fellow programmers would probably shoot me

  3. #3
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Originally posted by kleinma
    all I know is if I used line numbers fellow programmers would probably shoot me
    Nah, lines numbers are an essential when using Erl.

    And when you have a large project, finding a bug can be a big problem. I've used this method with success.

    You don't need all code numbered. Just a subroutine(or a few) that you think is causing an error, or could be.

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    I am not putting down the tip, I am sure it can be used in certain situations. All I am saying is that in some group development environments, using line numbers will get your shot.. thats all

  5. #5

    Thread Starter
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969
    I am not putting down the tip, I am sure it can be used in certain situations. All I am saying is that in some group development environments, using line numbers will get your shot.. thats all
    I used MZTools to put the line numbers in the project automatically and when I was done I used it to take them back out. That's just one of the options available with MZTools. If you are not familiar with the product you should check it out at www.mztools.com. It's free and I've used it for quite a while with no problems.

  6. #6
    Addicted Member JRSofty's Avatar
    Join Date
    Jan 2004
    Location
    Somewhere in Germany
    Posts
    149
    I don't know if you guys have heard of the company "The Mandelbrot Set" TMS for short but they write programs exclusively in VB and they suggest the use of Erl and line numbers for debugging. Although they do suggest the removal after the testing is complete.

    These guys are supposedly the top in VB programming.

  7. #7
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667
    I always use line numbers when programming the Erl is a life saver in a large project, but when compliing remove them. I use
    MZtools add-inn this will automically add and remove line numbers.

  8. #8
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    Better to do:-

    VB Code:
    1. Public Sub DivideByZero()
    2. On Error GoTo HandleError
    3. Dim x As Long
    4. Dim y As Long
    5.  
    6.    y = 5
    7.    MsgBox y / x 'error
    8. Exit Sub
    9.  
    10. HandleError:
    11.    Debug.Print "Error on line " & Erl
    12.    Exit Sub
    13.    Resume
    14. End Sub

    Then, when debugging put a breakpoint on the Debug.Print line and if your code hits said line move the execution pointer to Resume then hit F8 and it will take you right to the line that caused the error.

  9. #9
    Addicted Member JRSofty's Avatar
    Join Date
    Jan 2004
    Location
    Somewhere in Germany
    Posts
    149
    But not with out the line numbers

    VB Code:
    1. Public Sub DivideByZero()
    2. On Error GoTo HandleError
    3. Dim x As Long
    4. Dim y As Long
    5.  
    6. 10   y = 5
    7. 20  MsgBox y / x 'error
    8. Exit Sub
    9.  
    10. HandleError:
    11.    Debug.Print "Error on line " & Erl
    12.    Exit Sub
    13.    Resume
    14. End Sub

    This will work without the line numbers Erl only outputs 0

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