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
LVL 1
cescentmanAsked:
Who is Participating?
 
David LeeCommented:
Yes, it would require that on every line.  That's why I said it's not very clean.
0
 
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.

Cheers!
0
 
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.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

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

All Courses

From novice to tech pro — start learning today.