Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Debugging

Status
Not open for further replies.

gust1480

Programmer
Mar 19, 2002
148
PH
Hi! Can anyone please tell me if there is a way for me to determine where exactly in my code an error occurred?! CAn i get it's line number? Is there such a thing? THanks!
 
Yes you can use line numbers:

Sub Sample
Const cstrRoutineName as string = "Sample"
On Error GoTo ErrHandler
10 Debug.Print "Hello from Line 10"
20 Debug.Print "Hello from Line 20"
30 Debug.Print "Hello from Line 30"
40 Exit Sub
ErrHandler:
50 MsgBox "Error " & Err.Number & " in procedure """ & cstrRoutineName """ in module """ & mcstrModuleName & """ near line " & Erl & " """ & Err.Description & """"
60 Resume Next
End Sub

You can use the Erl function to return a line number.

I have a constant in each routine (cstrRoutineName) and each module (mcstrModuleName) that I can then use to identify the location of an error.

The MZ Tools add-in has a line-numbering feature that makes adding/removing line numbers much easier than doing it manually.

Andy
--
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
 
When you're running the code in the IDE, when the error occurs and the code terminates, click on the button that says Debug, and it will take you to the line where the error is. You have to comment out the error handler to do this, though.

Lee
 
>>You have to comment out the error handler to do this, though.

You don't have to comment out the error handler. If you right-click and do Toggle and then Choose Break on All Errors, then it will stop in the IDE when there is an error regardless if you have error handling or not.
 
You can use the Erl function to return a line number.

I have a constant in each routine (cstrRoutineName) and each module (mcstrModuleName) that I can then use to identify the location of an error.

The MZ Tools add-in has a line-numbering feature that makes adding/removing line numbers much easier than doing it manually.

I make the Erl function part of the error display using MZ Tools to take out the line numbers when I'm working on it and put them back when I make the exe. It can be very helpful. Here's what I display:

Err.Number_
Err.Source
Err.Description
Erl

 
We have a common error handling function that sticks information up for the customer to report back to our tech_support department. If I am trying to find where an error occurs therefore, my first point of call is to slap a breakpoint in the common function, then examine the call stack (using view callstack).

mmilan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top