|
-
May 3rd, 2004, 11:51 AM
#1
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.
-
May 3rd, 2004, 02:49 PM
#2
all I know is if I used line numbers fellow programmers would probably shoot me
-
May 3rd, 2004, 03:17 PM
#3
So Unbanned
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.
-
May 3rd, 2004, 03:20 PM
#4
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
-
May 4th, 2004, 05:30 AM
#5
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.
-
May 4th, 2004, 06:00 AM
#6
Addicted Member
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.
-
May 4th, 2004, 06:13 AM
#7
Fanatic Member
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.
-
May 4th, 2004, 08:02 AM
#8
Better to do:-
VB Code:
Public Sub DivideByZero()
On Error GoTo HandleError
Dim x As Long
Dim y As Long
y = 5
MsgBox y / x 'error
Exit Sub
HandleError:
Debug.Print "Error on line " & Erl
Exit Sub
Resume
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.
-
May 4th, 2004, 08:07 AM
#9
Addicted Member
But not with out the line numbers
VB Code:
Public Sub DivideByZero()
On Error GoTo HandleError
Dim x As Long
Dim y As Long
10 y = 5
20 MsgBox y / x 'error
Exit Sub
HandleError:
Debug.Print "Error on line " & Erl
Exit Sub
Resume
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|