Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VBScript

How to Debug Visual Basic Script with Visual Studio

4.52/5 (15 votes)
29 Nov 2019CPOL1 min read 144.7K  
This tip shows how easy it is to debug the VBScript by using Visual Studio Debugger

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:

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":

Start debugging

Useful Links and Information

  1. Creating And Using Scripts - http://wsh2.uw.hu/ch01d.html#20
  2. How To Debug WSH, VBScript And JScript
  3. https://stackoverflow.com/questions/23210905/can-you-debug-vbscript-in-visual-studio

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)