A common feature of integrated development environments is the ability to debug, or find and fix errors in, script that you have written. When you debug script, you can either debug when a script error occurs or set a breakpoint by adding a debug statement to the script. A debug statement tells the debugger when to suspend execution and allow you to step through your script and examine its behavior. This article explains how to add a debug statement to a script.
-
In Microsoft Office InfoPath, open the form template that contains the script.
-
On the Tools menu, point to Programming, and then click Microsoft Script Editor, or press ALT+SHIFT+F11 to open Microsoft Script Editor (MSE).
-
In the script, place the cursor where you want to add a debug statement, and then do one of the following:
-
To add a debug statement in the Microsoft JScript scripting language, type the debugger; statement.
-
-
To add a debug statement in the Microsoft Visual Basic Scripting Edition (VBScript) scripting language, type the Stop statement.
-
The following example demonstrates how to use the debug statement in the OnLoad event handler by using JScript syntax:
function XDocument::OnLoad(eventObj)
{ debugger; } -
Click Save in MSE, or press CTRL+S.
-
Switch to InfoPath.
-
On the Standard toolbar, click Preview, or press CTRL+SHIFT+B.
-
In the Just-In-Time Debugging dialog box, click New Instance of Microsoft Script Editor, and then click Yes.
-
In the Step Into Remote Procedure Call dialog box, click Script, and then click OK. MSE opens in debug mode and a yellow arrow indicates where execution was suspended.
Tip: With MSE in debug mode, you can use all of the debugging features that it provides. This includes setting breakpoints, stepping through program statements, and viewing any of the debugging windows such as the Watch, Immediate, and Call Stack windows.
-
If you want to stop debugging your script, click Stop Debugging on the Debug menu, or press SHIFT+F5 in MSE.