dcsimg
Results 1 to 17 of 17

Thread: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2019
    Posts
    142

    I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    Less well-known is the ERL function which gives you the line number where an error occurs. Most developers don't use this because this function returns 0 if the crashing line isn't numbered.

    The trick is to number all your lines before you deploy your application to your users. If you do that, the ERL function identifies exactly where a crash occurs:
    Code:
    Private Sub Form_Load()
    SampleErrorWithLineNumbers
    End Sub
    Code:
    Sub SampleErrorWithLineNumbers()
    
         Dim dblNum As Double
         Dim dblRnd As Double
    
    10   On Error GoTo PROC_ERR
    
         ' Randomly crashes on a line below:
    20   dblRnd = Rnd()
    
    30   Select Case dblRnd
           Case Is < 0.2
    40       dblNum = 5 / 0
    50     Case Is < 0.4
    60       dblNum = 5 / 0
    70     Case Is < 0.6
    80       dblNum = 5 / 0
    90     Case Is < 0.8
    100      dblNum = 5 / 0
    110    Case Else
    120      dblNum = 5 / 0
         End Select
    
    130  Exit Sub
    
    PROC_ERR:
    140  MsgBox "Value: " & dblRnd & vbCrLf & _
                "Error Line: " & Erl & vbCrLf & _
                "Error: (" & Err.Number & ") " & Err.Description, vbCritical
    End Sub
    In the silly example above all the dblNum equations crash because of division by zero. The Rnd function gives a random number between 0 and 1, and based on the value dies on one of the lines in the Select Case statement. The ERL function identifies which line and displays a message box:

  2. #2
    Hyperactive Member
    Join Date
    Aug 2016
    Posts
    371

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    how set number all code lines ?

  3. #3
    Lively Member gilman's Avatar
    Join Date
    Jan 2017
    Location
    Bilbao
    Posts
    66

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    Quote Originally Posted by xxdoc123 View Post
    how set number all code lines ?
    You can put it manually, or you can find a addin than do it for you, like MZTOOLS, you have to pay, or http://www.vbforums.com/showthread.p...w-open-sources, it is for free

  4. #4
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    314

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    VBIDEUtils can add/remove lines number.

    I use it in all my projects, and with the Error Handler, I can know where an error occurs on the clients sites

  5. #5
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,603

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    I'm using my VbCodeLines.exe utility in unattended build.bat scripts to (first copy all source files in a separate folder then) put line numbers to all source files references in the .vbp project file.

    cheers,
    </wqw>

  6. #6
    Member
    Join Date
    Oct 2019
    Posts
    35

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    Hi Bernie,

    superb ! , and in addition your code can be used with the GwBasic.

    … A wonderful world.

  7. #7
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,931

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    In an enhanced VB, all this should be automatic or with integrated functions:

    Automatically assign line numbers and a toggle button to see/hide the line numbers.
    A compilation option where, in case of error, to show an error message with the line number instead of crashing.

    That's simple logic of what to expect in a developed language.

  8. #8
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,603

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    Unfortunately while in other languages collecting a stack-trace w/ line numbers can happend post exception and does not affect working code performance, in VB6 code lines *do* generate extra instruction to set (hidden) Erl variable before executing each statement. Yikes!

    cheers,
    </wqw>

  9. #9
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,931

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    Quote Originally Posted by wqweto View Post
    Unfortunately while in other languages collecting a stack-trace w/ line numbers can happend post exception and does not affect working code performance, in VB6 code lines *do* generate extra instruction to set (hidden) Erl variable before executing each statement. Yikes!

    cheers,
    </wqw>
    And couldn't that be changed (in a language refactoring) to work like other languages?

  10. #10
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,047

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    Quote Originally Posted by gilman View Post
    You can put it manually, or you can find a addin than do it for you, like MZTOOLS, you have to pay, or http://www.vbforums.com/showthread.p...w-open-sources, it is for free
    I used to use MZTOOLS when I used VB6. Awesome addin. Lots to like about it, but one thing that stands out was the dotted lines that showing which if's belonged with which else's and end if's. If your still coding in VB6 MZTOOLS is well worth the investment.

  11. #11
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,603

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    Quote Originally Posted by Muddy View Post
    . . . but one thing that stands out was the dotted lines that showing which if's belonged with which else's and end if's.
    LOL, there is no such feature in MZ-Tools. . . but yes, it's awesome.

    Must be some other add-in with the dotted line in the IDE editor after all :-))

    cheers,
    </wqw>

  12. #12
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,047

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    Quote Originally Posted by wqweto View Post
    LOL, there is no such feature in MZ-Tools. . . but yes, it's awesome.

    Must be some other add-in with the dotted line in the IDE editor after all :-))

    cheers,
    </wqw>
    ya know it has been a really long time. I could be remembering wrong, or confusing it with an auto indenter or something. Hell maybe I even had another addin back then . . .

  13. #13
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,991

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    I would imagine that some of the newbies and novice users may find the tip useful. Those of us who have been around a while are generally well aware of the ERL option, It has been around long before VB. I used it a bit back in GWBasic but once line numbers were no longer required as part of the code I pretty much stopped using it though have added line numbers to a troublesome routine to help track down an end user error when I could not reproduce it myself. Most of the time it is not needed.

  14. #14
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,047

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    Quote Originally Posted by wqweto View Post
    LOL, there is no such feature in MZ-Tools. . . but yes, it's awesome.

    Must be some other add-in with the dotted line in the IDE editor after all :-))

    cheers,
    </wqw>
    OK I looked it up .. it was codesmart I was thinking about. very much worth a look if you're still coding in VB6
    https://www.axtools.com/products-codesmart-vb6.php

  15. #15
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,146

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    If you use Erl as proposed consider that you do not have to number every line in your code. If an error occurs on a line without a number it will report the number of the first line above it which is numbered, it only reports zero if there are no numbered lines above it . So it is usually possible to just to 'bracket' sections of code with a numbered line at the top and a numbered line at the bottom.
    It is also quite crucial to identify the name of the Sub / Function where the error occurred in the Error message.

  16. #16
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,146

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    Dupe post

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Aug 2019
    Posts
    142

    Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES

    Quote Originally Posted by Magic Ink View Post
    If you use Erl as proposed consider that you do not have to number every line in your code. If an error occurs on a line without a number it will report the number of the first line above it which is numbered, it only reports zero if there are no numbered lines above it . So it is usually possible to just to 'bracket' sections of code with a numbered line at the top and a numbered line at the bottom.
    It is also quite crucial to identify the name of the Sub / Function where the error occurred in the Error message.
    works without line numbers it still reports the line number

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width