-
Oct 20th, 2019, 10:04 PM
#1
Thread Starter
Addicted Member
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:
-
Oct 20th, 2019, 11:42 PM
#2
Fanatic Member
Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES
how set number all code lines ?
-
Oct 21st, 2019, 01:24 AM
#3
Addicted Member
Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES
Originally Posted by xxdoc123
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
-
Oct 21st, 2019, 01:30 AM
#4
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
-
Oct 21st, 2019, 01:52 AM
#5
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>
-
Oct 21st, 2019, 02:40 AM
#6
Member
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.
-
Oct 21st, 2019, 05:48 AM
#7
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.
-
Oct 21st, 2019, 06:11 AM
#8
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>
-
Oct 21st, 2019, 06:33 AM
#9
Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES
Originally Posted by wqweto
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?
-
Oct 21st, 2019, 09:12 AM
#10
PowerPoster
Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES
Originally Posted by gilman
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.
-
Oct 21st, 2019, 11:33 AM
#11
Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES
Originally Posted by Muddy
. . . 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>
-
Oct 21st, 2019, 12:13 PM
#12
PowerPoster
Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES
Originally Posted by wqweto
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 . . .
-
Oct 21st, 2019, 01:19 PM
#13
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.
-
Oct 21st, 2019, 01:31 PM
#14
PowerPoster
Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES
Originally Posted by wqweto
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
-
Oct 21st, 2019, 01:31 PM
#15
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.
-
Oct 21st, 2019, 01:33 PM
#16
Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES
-
Oct 21st, 2019, 05:26 PM
#17
Thread Starter
Addicted Member
Re: I want to share this with you all: FIND LOCATION LINE NUMBER WHERE APP CRASHES
Originally Posted by Magic Ink
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|