Returning line numbers in programmatically VBS

Is there a way of returning the line number from within a script. In other words:-

Is there a function I can write so that:

MsgBox "This is line " & ??
MsgBox "This is line " & ??
MsgBox "This is line " & ??

Produces the output:-

This is line 1
This is line 2
This is line 3
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.

David LeeCommented:
Greetings, cescentman.

If you mean an automatic counter that keeps track of the current line of code being executed, then I assume there is one, but it's not exposed in any way that I've been able to discover.

cescentmanAuthor Commented:
I guess that's what I am after - shame it's not usable. I can't see any other way of achieving this.
David LeeCommented:
There is another way, but it's not real clean.  You can use VBScript's ability to stack multiple commands on one line to achieve this.  Something like this:

    Dim intLine
    intLine = intLine + 1: WScript.Echo intLine
    intLine = intLine + 1: WScript.Echo intLine

Or you could modify this a bit.

    Dim intLineNumber
    LineNumber 1: WScript.Echo intLineNumber
    LineNumber 1: WScript.Echo intLineNumber

    Sub LineNumber(intChange)
        intLineNumber = intLineNumber + intChange
    End Sub

This would allow you to easily subtract from the line number as well as add to it.
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

cescentmanAuthor Commented:
Don't think this would help in the circumstances I have in mind. From how I understand what you are suggesting I would need this on every line of the script - it would make it very unreadable. Thanks for the suggestion though.
David LeeCommented:
Yes, it would require that on every line.  That's why I said it's not very clean.

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
cescentmanAuthor Commented:
Shame there wasn't another way as this is just too clunky. Thanks for tryinig anyway.
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
Windows Server 2003

From novice to tech pro — start learning today.