[Zz] Debug VBScript with Visual Studio

Source: Internet
Author: User

 

Http://blog.theopensourceu.com/2009/05/debug-vbscript-with-visual-studio/

 

For a project that I work on at my primary employer, we use VBscript inside
Of DTs
Packages. Until this project, I 've not had too much experience with VBScript. What
I 've found most frustrating about the language is the inability to step though
The Code... Until a recent discovery. I 've found that if I save the target code
My local machine as a vbs file and execute it with wscript.exe, I can attach
Debugger to it.

I 've discovered this by poking around and I don't know too much about
Wscript.exe. I'm sure if you Google it, you can find more about it.

For this to work, you'll need a copy of visual
Studio installed. I am not sure if any of the express editions will work.
Drop a line in the comments if you find it will. As a quick walk though:

  1. Save your code as a vbs file. Don't forget to call main (or your main)
    Function as wscript won't automatically call main.
  2. Open a command prompt.
  3. Navigate to the location of the file.
  4. Type:Wscript.exe filename. vbs // D // X
  5. You shoshould be prompted to select a debugger, select a new instance of either
    Visual
    Studio 2003,200 5 or 2008.
  6. Visual
    Studio will open up and break at the very first line.
  7. Step though the code.

For an example, save the following as "example. vbs" on your desktop.

 

MsgBox "Starting Script!"Dim i : i = 0Const C_Max = 100Dim sPrimeNumberList : sPrimeNumberList = "Prime Numbers: " & vbCrLfFor i = 0 to C_MaxIf IsNumberPrimeNumber(i) Then     sPrimeNumberList = sPrimeNumberList & cStr(i) & ", "EndIfNextMsgBox sPrimeNumberListMsgBox "Script Completed."PublicFunction IsNumberPrimeNumber(ByVal iNumber)Dim bIsPrime : bIsPrime = TrueFor j = 2 To iNumber\2  bIsPrime = iNumber Mod j > 0IfNot bIsPrime ThenExitForNextIsNumberPrimeNumber = bIsPrimeEndFunction

 

 

Open a command prompt and navigate to your desktop:

Command Prompt for debuggingvbscript from visual
Studio

Once there, type in the following:

 

1 Wscript example. vbs // D // X

 

You shoshould then be presented with a dialog similar to the following:

Visual
Studiodebuggingvbscript

Once you make a selection, you shocould get something like the following:

Debuggingvbscript from visual
Studio

From here, I'll assume you are familiar enough with visual
Studio to play with the debugger and learn how it works. When debuggingvbscript, I 've
Found that you don't have all the options that you might be used to such as step
In to, but for me simply having this much is a life saver.

ToGet around the step-in-to thing, I simply useRun
To cursor
. It works like a charm.

Update:I just found that (at least on this computer) and in
Visual
Maxcompute Studio 2003, I have all my standard code-Stepping buttons available. I'm not
Sure why on my work computer I only have step-over but either way, this is still
A life saver.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.