Microsoft Office 2000/Visual Basic Programmer's Guide |
The Microsoft Script Debugger provides a comprehensive debugging environment for working with both client- and server-side script in HTML pages and Active Server pages (ASP). The Script Debugger works with VBScript and Microsoft JScript. It provides all of the debugging tools described in the previous section, with the exception of watch expressions. However, you cannot use the Print method of the Debug object to output information to the Script Debugger's Immediate window.
The Microsoft Script Debugger and its supporting documentation are available from the Microsoft Scripting Technologies Web site at http://msdn.microsoft.com/scripting/.
You can debug the script you add to an Office document by using the debugging capabilities of the Microsoft Script Editor. For more information about using the Script Editor to work with the HTML code and script in an Office document, see Chapter 12, "Using Web Technologies." For information about using the Script Editor with data access pages, see Chapter 5, "Working with Office Applications."
To enable script debugging in the Script Editor, click Options on the Tools menu, and then click Debugger in the hierarchical view of options. Select the Just-In-Time debugger and Attach to programs running on this machine check boxes. Once these options have been selected, errors in script will generate a message box that gives you the option of opening the Script Editor's debugger.
You can use the Script Editor to set breakpoints in your script. These breakpoints work just like they do when you are debugging VBA code in the Visual Basic Editor. The Script Editor also has the following debugging windows that you can use to work with script: Immediate, Locals, Watch, Threads, and Call Stack. These windows give you views into your running script in the same way that they let you debug VBA code when they are used in the Visual Basic Editor. There is one difference you need to be aware of however. In the Script Editor, the script debugger is not as tightly integrated with the host application as the VBA debugger is in Office applications. This means that the Immediate and Watch windows in the Script Editor are not active unless your script is stopped at a breakpoint. In other words, you can't set up a Watch variable in the Script Editor and watch its value change as your script executes.
You should remember to close the script debugger each time you are finished debugging or each time you return to running your script. This is because each time you open the debugger, a new instance of the Script Editor is created. If you don't close these instances, you can end up with a lot of open windows on your desktop. To avoid opening and closing the script debugger, you can create a debug log file to record errors that occur on a page while a script is running. You can also open a separate window to display the logged error information. To see an example of script that displays error information in a separate window as script is running, see the LogScriptErrors.htm file in the ODETools\V9\Samples\OPG\Samples\CH08 subfolder on the Office 2000 Developer CD-ROM.