• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4015
  • Last Modified:

VB6: gtting the line number on error log

I have an application written in VB6. On Error occure - the program writing to ErrorLog (txt file).
How can I get on me ErrorLog on which Sub and line the error occured?
Tks
0
2Angel
Asked:
2Angel
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
The only way you can do that would be to pass the sub name in your error handler, which means you'll have to manually type it into every error log call.  Like...

error_handler:
   call fn_log_errors(err.number, err.description, "modMain.sbDoThis")

You could save some time and use a module-level string for the form-module-class name...
0
 
2AngelAuthor Commented:
this  exactly what I do - but I need to get the line number - is it possible?
0
 
TaconvinoCommented:
You could use Erl (undocumented) function.  Here's a nice article about pros and cons using this:

http://www.informit.com/articles/article.asp?p=25180&rl=1

MZTools can make a nice job numbering lines for you.

+TCV
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
samstarkeyCommented:
I agree with Taconvino,

MZTools is the way to go

http://www.mztools.com/v3/mztools3.htm

0
 
dancebertCommented:
One tricky part about Erl() is that the error occured at or after the line number returned by Erl().  If you don't number every executable line the returned value can be deceiving.

For example:

10    x = 310
20    y = 213
        z = 1 / 0
30    result = x + y + z

The division by zero error occurs at the unnumbered line between 20 and 30, so  Erl() returns 20.

At one time it was a documented function, but I don't recall when or why Microsoft removed it from the docs.
0
 
2AngelAuthor Commented:
Thank you for your comments.

Why on VBS I get the line number and even the chr' cause the error with out numbering the lines?

Tks!
0
 
2AngelAuthor Commented:
Also, something to think about: when error ocure the program jump to the Error Handler and the, if there is a command Resum Next, the program jump back to the next line that cause the error - how does it know where to jump back? Can I retrieve that data (the line bumber to jump back)?
0
 
dancebertCommented:
>Can I retrieve that data (the line bumber to jump back)?

No.
0
 
2AngelAuthor Commented:
but the compiler "know" to which line to jemp back - where "he" stor that information?
0
 
dancebertCommented:
>where "he" stor that information?

Someplace inaccessible to the VB programmer.  Just another example of the VB architects keeping low level details away from the programmer.
0
 
2AngelAuthor Commented:
Thanks!
Is there another "VB" (VB.NET?) that "give" that information "builtin"?
0
 
dancebertCommented:
I don't know, I'm still a beginner at VB.Net.
0
 
2AngelAuthor Commented:
OK - do you know source code (I need a code) to "make" those numbering?
0
 
dancebertCommented:
>OK - do you know source code (I need a code) to "make" those numbering?
MZTools, as Taconvino  already suggested.

I usually want to add line numbers to some subs or just some parts of a sub.  I copy the code selection into Textpad where I run a macro that adds line numbers, then I paste the code back into VB.  I've read that Notepad++ does line numbering, so one doesn't have to write a macro.  It's a free replacement for Notepad.  see http://notepad-plus.sourceforge.net/uk/site.htm
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now