Introduction
If you are programming with Visual Basic Script, you have difficulties to find a bug in your script: there isn't any debugger for VBS! This tip shows how you can easily use Visual Studio for this.
Background
Normally, you start a script from the command line like this:
Quote:
cscript.exe myScript.vbs
In order to debug your script you only need to add the parameter /x
:
Quote:
cscript.exe /x myScript.vbs
This will set a breakpoint and throw an immediate exception, which starts the debugger immediately after the script starts running.
The following dialog will be shown where you can choose Visual Studio and step into your VBS code:
Not all versions of Visual Studio support Just-In-Time debugging, especially the VS Express Editions are the problem. You recognize whether your version supports the JIT debugging as follows:
Quote:
Visual Studio -> Tools -> Options -> Debugging -> Just-In-Time
A good news: the new Visual Studio 2019 (even the Community Edition) do support the VBS debugging!
Another possibility is to bind the VBS debugger as an external tool: Tools -> External Tool:
Then, just open the file you want to debug with Visual Studio (via File --> Open --> File...)
In order to start the debugger, just click "Tools / VBScript Debug":
Useful Links and Information
- Creating And Using Scripts - http://wsh2.uw.hu/ch01d.html#20
- How To Debug WSH, VBScript And JScript
- https://stackoverflow.com/questions/23210905/can-you-debug-vbscript-in-visual-studio