Share this Page URL

Chapter 5. Using Visual Basic to Automat... > Handling Errors and Debugging Code - Pg. 173

Using Visual Basic to Automate Your Database 173 Suspending the execution of code You can also suspend code by adding a Stop statement to a procedure or by pressing Ctrl+Break while the code is running. · Setting a watch By setting a watch, you can keep an eye on the value of a variable or an ex- pression as you step through your code. You can see when the variable is initialized, when it changes its value, and the value it changes to. The Debug toolbar includes the Quick Watch button. To set a quick watch, select the expression whose value you want to see, and then click Quick Watch. The Quick Watch dialog box then displays the expression and its current value. Click Add to add the expression to the Watches window. The Watches window displays the values of the expressions you've selected as the procedure runs. You can also add a watch expression by clicking Add Watch on the Debug menu. If an expres- sion is already selected in the Code window, that expression is displayed in the Add Watch dialog box. Otherwise, enter the expression you want to examine. The expression can be a variable, a property, a function call, or any other valid expression. You can also select an ex- pression in the Code window and drag it to the Watches window to set a watch. · Using the call stack When you click Call Stack on the Debug toolbar, the Visual Basic Editor displays the procedures that the procedure you're working with has called in the order in which it called them. The most recently called procedure is displayed at the top of the list. To display the statement that calls the next procedure in the list, click the Show button in the Call Stack dialog box. Ignoring error handling when debugging When you are debugging a procedure, you might want to exclude the procedure's error-handling code. On the General tab of the Options dialog box, select Break On All Errors. With this option selected, the error-handling code is not executed, and the Visual Basic Editor enters break mode when an error occurs. Using the Debugging Tools with the CallExample Procedure In the following steps, we'll use the debugging tools to review the procedure named CallExample. Debug code 1. 2. With the HelloWorld5 database open, press Alt+F11 to open the Visual Basic Editor. In the Project Explorer, double-click the node for modDemonstrations. In the Code window, select the procedure named CallExample from the Procedure list at the top of the Code win- dow. The code looks like this: