Results 1 to 3 of 3

Thread: Tips for Debugging Visual Basic for Applications Code

  1. #1
    Join Date
    Apr 2009
    Posts
    515

    Tips for Debugging Visual Basic for Applications Code

    Hi friends,
    I would like to share some of tips related to the debugging of Visual Basic for Application (VBA) Code. Hope that someone gets help from this.!! The general procedure for debugging Visual Basic for Applications is to divide the processes into sub-large smaller procedures to ensure that the individual steps of each sub-procedure work correctly, then combine the sub-procedures one after the other until all the code works correctly.

    Using the Debug window : You can use the Immediate pane of the Debug window to run individual lines of Visual Basic for Applications or to check the values of variables. In the Debug window, you can test and debug a function and sub-procedures to verify the value of a field, control of a property setting of a variable or of expression. Finally, you can view the result of an expression when executing code. For an example on how to use the Debug window, follow these steps :
    1. Open your function module in Design view.
    2. In the View menu, click Debug Window.
    3. Run your function in the pane of the Debug window by inserting the following line and then pressing ENTER:
    4. ? <FunctionName> ()
    5. where <FunctionName> is the name of your function. Be sure to include the parenthesis in all arguments expected by your office.


    Using a break-point to suspend execution of code : When you suspend the execution of a Visual Basic for Applications, the code is not canceled, but the pauses between the executing instruction. For Visual Basic for Applications pause in the execution of your code, you can insert a breakpoint. For example, if the first part of your code works correctly, but this is not the case for other parts, you can find one that does not work correctly as follows :
    1. To insert a breakpoint immediately after the section of code that works, move the insertion point of the first line of your code where you want to place a breakpoint.
    2. Click Toggle Breakpoint in the Debug menu (or the Run menu in version 7.0.). The line appears in bold, which indicates a breakpoint set on this line.
    3. Run the function in the Debug window. When code execution reaches the breakpoint, processing is suspended and the line containing the breakpoint is selected. You can then check the value of variables in the code.
    4. The value username appears in the Debug window. If the value is correct, check the other variables. If the value is incorrect, check the previous lines of code to see where this variable has received an incorrect value.

  2. #2
    Join Date
    Apr 2009
    Posts
    515

    Re: Tips for Debugging Visual Basic for Applications Code

    Inserting a watch expression in Visual Basic for Applications : A watch expression is an expression that you check in the Debug window. You can observe the values of watch expressions that you choose in the Watch pane. You can also use Instant Watch to see the value of an expression that has not been designated as watch expression. To add a watch expression to the Watch pane, follow these steps :
    1. Open the Debug window by pressing CTRL + G.
    2. In the Debug menu (or Tools menu in version 7.0), click Add Watch.
    3. In the Expression box, type a variable, a property, a function call or any other valid expression.
    4. In the background, set the scope of the term you are watching by selecting the name of the Procedure and Module name.
    5. In the type of spy, click on the desired option to determine how the expression is evaluated.

    When running your code is suspended, you can click Quick Watch on the Debug menu in Microsoft Access 97 to check the value of an expression that has not been designated as watch expression. You can also choose a phrase in your code and click QuickWatch for spying.

    Use the Calls dialog box to follow the procedures nested : The dialog box displays the Calls list of all active procedure calls. These calls are in an application, the procedures that were started but were not executed. You can use the Calls dialog box to monitor the execution of an application as it executes a series of procedures. You can view the calls from the Debug window by clicking the Build button. The dialog box displays the Calls list of all active procedure calls in a series of nested procedure calls. It places the active procedure call the oldest at the bottom of the list and add procedure calls following up. You can use the Show button on the dialog box calls to display the statement that calls the next procedure listed in the dialog box calls. If you select the proceedings in the Calls dialog box, and then click View, Visual Basic for Applications displays the current instruction to which execution has been suspended.

  3. #3
    Join Date
    Apr 2009
    Posts
    515

    Re: Tips for Debugging Visual Basic for Applications Code

    Using the Locals pane : The Locals pane of the Debug window has three columns: Expression, Value, and type (Context, or in version 7.0). The Expression column begins with the current module (for a standard module) or by the current instance of a class (a class module). The column expression is organized as a hierarchical tree of information starting from the current module to show all the module-level variables in the current module. The Value column contains the values of objects module. You can change the value of a module-level variable in the Debug window in order to test the behavior of your module. The Type column contains the type of object-level module. It can be very useful to inspect the value of a selected variable in the Locals pane to debug your module. Modifying a variable value in the Value column of the Locals pane can also be observed for the effect it has on other parts of the module.

Similar Threads

  1. Tips for developing Visual Basic application
    By SpearMan in forum Tips & Tweaks
    Replies: 2
    Last Post: 23-04-2012, 03:05 PM
  2. Replies: 4
    Last Post: 13-09-2011, 08:23 PM
  3. Protect Visual Basic for Applications code
    By Jalela in forum Windows Software
    Replies: 6
    Last Post: 10-07-2011, 11:13 AM
  4. Issue with Visual Basic Code
    By Harshini in forum Software Development
    Replies: 1
    Last Post: 10-04-2009, 04:21 PM
  5. Visual Basic tips
    By Ximen in forum Software Development
    Replies: 3
    Last Post: 22-01-2009, 03:36 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,849,090.14511 seconds with 16 queries