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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the best way to debug a script?

Status
Not open for further replies.

JV28132

Programmer
Apr 19, 2010
11
US
I am using Visual Studio to debug vbscripts. However, when the script runs in Visual studio editor, it does not necessarily run when the script is executed.

I would like to know how the vbscript is best debugged. Is there a debugger out there that will allow a step through process or do you just have to display messages along the way.

Any suggestions will be greatly appreciated.

Thanks so much!
 
There are different kinds of errors. Syntactical and logical. Do you have any inkling which type you are encountering?

If you have On Error Resume Next turned on then you might initially want to comment that out and the script will report line numbers and position where you might be missing closing parenthesis etc. Once you have made sure that the errors are not from syntax, then you should look for logical errors.

My preferred method is to have the script report error numbers and error descriptions. To do that you first need to turn on On Error Resume Next.

Once that is done you can report error number and description like so:

Code:
If Err.Number <> 0 Then
  Wscript.Echo Err.Number & "  " & Err.Description.
End If

If you would like to isolate where an error might be occurring you can turn off the On Error Resume Next with On Error GoTo 0



I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Yes, this is very helpful. Most of the time they are run-time errors. I can typically find the syntax but I am used to stepping through the logic during run-time. Since that is not possible, and we need to keep the on error resume next in the code, this will help alot.

Does placement of this code matter? does it need to be directly following the on error resume next?
 
No you want that to follow after you have done something in the script that might cause an error.

You can also clear errors with
ERR.CLEAR

Something to think about, say you are creating a user ID in AD. Everything LOOKS like it went great yet you are getting an error -2147463168. You might start scratching your head, the ID was created with all the attributes you told it to so why the error? This particular "error" tells you that the ID was created without an expiration date. It is informational and not an actual error that you need to correct. It is for this reason that I like to trap those errors and account for them in my code.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top