Debugging of VBA Programs

Source: Internet
Author: User

Debugging VBA Programs: Setting breakpoints, stepping through, setting up a watch Window

The Acces VBE programming environment provides a complete set of debugging tools and debugging methods. Master the use of these debugging tools and debugging methods, can quickly and accurately find the problem, and constantly modify, to improve.
  First, the "breakpoint" concept
A "breakpoint" is a point in a particular statement on a procedure that breaks the execution of a program. The "breakpoint" setting and use runs through the entire process of program debugging.
There are 4 ways to set and cancel breakpoints:
(1) Select the statement line, and click Toggle Breakpoint on the Debug toolbar to set and cancel breakpoints.
(2) Select the statement line and click the Toggle Breakpoint item on the Debug menu to set and cancel breakpoints.
(3) Select the statement line, press the keyboard "F9" key to set and cancel "breakpoint".
(4) Select the statement line, move the mouse cursor to the beginning of the row click to set and Cancel breakpoints.
In the VBE environment, the set "breakpoint" line is shown in "mole" bright red, 8.25.

  Second, the use of debugging tools
In the VBE environment, right-click on the menu blank, pop up the shortcut menu, check the "Debug" option to make it front "?" appears, the Debug toolbar opens. 8.24 shows.

The main button function descriptions in the Debug toolbar are shown in table 8.11.

Debugging tools are typically used in conjunction with breakpoints for various debugging operations. The following is a brief introduction to the use of some of the main debugging tools on the Debug toolbar.
1. Interrupt Tool button
Used to temporarily interrupt the operation of the program for analysis. At this point, the sequence breaks in the program produce a "yellow" light bar, shown in 8.25.
2. local Window tool button
Used to open the Local window window, as shown in 8.26. It automatically displays all variable declarations and variable values in the current process, from which you can observe various data information.

When the local window opens, the first item in the list is a special module variable. For a class module, define me. Me is a reference to the current class instance defined by the current module. Because it is an object reference, you can expand the display of all the properties and data members of the current instance.
In fact, the Me class module is also widely used in VBA programming, it does not need to be defined specifically, can be used directly. When you write a class module generally, you can use the Me keyword for instance references to the current module.
3. Immediate Window tool button
Used to open the Immediate Window window, shown in 8.27. In break mode, you can schedule some debug statements in the Immediate window, which are executed according to the content or scope displayed in the Immediate Window area. If you enter print VariableName, the value of the local variable is the output.

4. Monitor Window tool button
Used to open the Watch window, window, 8.28. In break mode, right-click the shortcut menu that pops up in the Watch Window area, select Edit Watch ... or add watch ... to open the edit (or add) window, modify or add the watch expression at the expression location, as shown in Figure 8.29, select Delete Watch ... Item deletes the existing watch expression.
By adding monitoring expressions to the Watch window, the program can dynamically understand the changes in the values of some variables or expressions
, and then have a clear judgement of whether the code is correct or not.
5. Quick Monitor Tool button
In break mode, first select a variable or expression in the program code area, and then click the QuickWatch Tool button, then open the QuickWatch window, 8.30, where you can quickly observe the current value of the variable or expression to achieve a quick monitoring effect. If you want, you can also click the Add button to add the variable or expression to the Watch window that is subsequently opened for further analysis.

Source: http://www.educity.cn/ncre/ncrefx/201011301007201217.htm

Debugging of VBA Programs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.