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?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Data DudeCommented:
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...

   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...
2AngelAuthor Commented:
this  exactly what I do - but I need to get the line number - is it possible?
You could use Erl (undocumented) function.  Here's a nice article about pros and cons using this:


MZTools can make a nice job numbering lines for you.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

I agree with Taconvino,

MZTools is the way to go


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.
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?

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

2AngelAuthor Commented:
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.
2AngelAuthor Commented:
Is there another "VB" (VB.NET?) that "give" that information "builtin"?
I don't know, I'm still a beginner at VB.Net.
2AngelAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.