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