Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get actual line number

Status
Not open for further replies.

RoMa68

Technical User
Feb 7, 2006
27
DE
How can i get the actual line number within the running vbscript?

At the moment for debugging i use a debug-switch an message-boxes:
If Debug <> 0 Then
MsgBox "227-Error reading XMLConfig"
End If
But on doing changes and adding lines i have to changes all following entries - how can i detect the actual line number?

Thanks in advance... MR
 
Depends on your editor.

In notepad ensure line wrap is off and press Ctrl+G then type the line number and you will be brought to that line.

Most other editors provide line numbers. For full debugging capabilities I suggest that you download Visual Web Developer Express (free from Microsoft). It supports vbscript and will let you debug while looking at the code the same way Visual Studio does. Do some searching on debugging in Visual Studio and you will learn how to "watch" variables and objects to see what values they hold while a script is processing.
You can use to help you configure the environment for better script testing.

Other editors that I have used are PrimalScript (expensive) and VBSEdit (inexpensive), but I have found the above free solution to work great.


I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
marc I may be wrong but I think he is asking if something like -

Code:
227-Error reading XMLConfig
dynamically changing to
Code:
231-Error reading XMLConfig
if he adds 4 lines of code into the VBscript. not in the actuall reading.

I don't know how to get that butI think thats what s being asked.

On the note a free editor I like is EmEditor it has a large code base it supports as well as color codes your entries and gives line numbers. Very nice for free.

My only complaint is once I have it made I save it to a vbs file I have to go into the vbs and clean it up for regular text editor view as it has its own fomat.
 
marc I may be wrong but I think he is asking if something like -

Code:
227-Error reading XMLConfig
dynamically changing to
Code:
231-Error reading XMLConfig
if he adds 4 lines of code into the VBscript. not in the actuall reading.

I don't know how to get that butI think thats what s being asked.

On the note a free editor I like is EmEditor it has a large code base it supports as well as color codes your entries and gives line numbers. Very nice for free.

My only complaint is once I have it made I save it to a vbs file I have to go into the vbs and clean it up for regular text editor view as it has its own format.
 
Turning off On Error Resume Next will give you the line and place int he line that the error actually occured so you don't want to hard code a line number in a msgbox for error handling.

using the product I have described will let you follow the values while the script processes.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
I'm using UltraEdit (does anybody use notepad for developping?) so i now the line numbers on coding.

On getting a real error I think this
>>>
If Err.Number <> 0 Then
If Debug <> 0 Then
MsgBox Err.Line & "263-Error # " & CStr(Err.Number) & " " & Err.Description
End If

Err.Clear ' Clear the error.
Server1Offline = 1
History = FormatDateTime(Now,vbGeneralDate)&", "&Err.Line &"263-Error # " & CStr(Err.Number) & " " & Err.Description
WriteLineToFile() 'write event to logfile
Else
Server1Offline = 0
End If
On Error GoTo 0
<<<
should give me the line-number. But I want to get the line-number on a simple message box like this
>>>
If Debug > 1 Then
WScript.Echo "253-login S1: " & strServer1 & ", U1: ", strUser1 & " P1: " & strPword1 & " D1: " & strDomain1
End If
<<<

Thanks MR
 
You cannot get the line number dynamically as the script is processing. If your goal is simply to provide information on where exactly in the script you are, then I would suggest using tags. So for instance:

If Debug > 1 Then
WScript.Echo "DEBUGTAG:LOGININFO: " & strServer1 & ", U1: ", strUser1 & " P1: " & strPword1 & " D1: " & strDomain1
End If

Then if you need to find the bit of code that generated the message you would just need to search for DEBUGTAG:LOGININFO.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top