Link to home
Start Free TrialLog in
Avatar of 2Angel
2Angel

asked on

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
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

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...
Avatar of 2Angel
2Angel

ASKER

this  exactly what I do - but I need to get the line number - is it possible?
ASKER CERTIFIED SOLUTION
Avatar of Taconvino
Taconvino

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree with Taconvino,

MZTools is the way to go

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

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.
Avatar of 2Angel

ASKER

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!
Avatar of 2Angel

ASKER

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)?
>Can I retrieve that data (the line bumber to jump back)?

No.
Avatar of 2Angel

ASKER

but the compiler "know" to which line to jemp back - where "he" stor that information?
>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.
Avatar of 2Angel

ASKER

Thanks!
Is there another "VB" (VB.NET?) that "give" that information "builtin"?
I don't know, I'm still a beginner at VB.Net.
Avatar of 2Angel

ASKER

OK - do you know source code (I need a code) to "make" those numbering?
>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