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

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
0
cescentman
Asked:
cescentman
  • 3
  • 3
1 Solution
 
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
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
David LeeCommented:
Yes, it would require that on every line.  That's why I said it's not very clean.
0
 
cescentmanAuthor Commented:
Shame there wasn't another way as this is just too clunky. Thanks for tryinig anyway.
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

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