IT tutorials
 
Office
 

Microsoft Access 2010 : TESTING AND DEBUGGING VBA CODE (part 3) - Call Stack, Run to Cursor

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Product Key Free : Microsoft Office 2019 – Serial Number
5/4/2013 9:00:42 PM

6. Call Stack

The Call Stack dialog box displays a list of the current active procedure(s) when you are stepping through code. An active procedure is one that is started but has not completed — and as you are beginning to realize, the list can grow rather quickly. You can access the Call Stack dialog box in several ways — you can press Ctrl+L or use the menu bar (View => Call Stack). Because the call stack is available only in break mode, access to the call stack is grayed out (disabled) when you are in Design mode.

THE CALL STACK

The Call Stack dialog box is a modal window and therefore cannot be left open when stepping through code. So, after you review the list of active procedures, you will need to close the dialog box in order to continue running the code.


The Call Stack dialog box is most beneficial when one procedure is calling another or if your code has nested procedures, whether they are in the same module or being called by other modules. When one procedure is called from another procedure, the dialog box displays the new procedure at the top of the list with the original (calling) procedure under it, thus the stacking effect. Figure 4 illustrates this stacking process. You will see that OverBudget was called by GoShopping, so OverBudget is listed first, and it is highlighted because it is the procedure being run. After a procedure is finished, it is removed from the stack. In this case, after OverBudget is run, GoShopping will be the only procedure in the stack.

Figure 4.

When you step through multiple procedures from different modules, or even from the same module, it can be a bit challenging to figuring out where a particular procedure is being called. To help find the start of any active procedure in the call stack, select the active (top) procedure in the list and either double-click the item or click the Show button. In the current example, the call stack was opened when OverBudget was called, so two procedures are listed.

To find out what line called OverBudget, you can double-click on GoShopping, the calling procedure. This puts a green pointer at the line in GoShopping, which called OverBudget. Figure 5 shows OverBudget still highlighted, because that's the current point in stepping through the code, and the green pointer at the call to OverBudget.

As you can see, the call stack is helpful when you are working with multiple procedures and trying to determine where errant data may be originating. It is also a handy tool to be used in conjuction with the other debugging tools when you need to decipher and work with someone else's application or modules.

Figure 5.

7. Run to Cursor

When testing your code, you will likely have many times that you don't want to run every line of code line-by-line, but executing the entire procedure at once isn't conducive to isolating and identifying the source of a problem. And, if the code includes loops, it can be very tedious to execute every line of the loop each time it needs to run. For example, consider the loop (While ... Wend) in the following code:

Sub CoffeeTime()
    Dim curLatteAllowance As Currency
    Dim curLattePrice As Currency
    Dim intNumLattes As Integer
    Dim curTotalExpenses As Currency

    curLattePrice = 3.5
    curLatteAllowance = InputBox( _
        "Enter the amount of money you have for lattes.", _
        "Latte Allowance")

    If curLattePrice <= curLatteAllowance Then
        curTotalExpenses = curTotalExpenses + curLattePrice
    Else
        MsgBox "You do not have enough funds to buy a latte", _

vbOKOnly, "Total Lattes"
        Exit Sub
    End If

    While curTotalExpenses < curLatteAllowance
        intNumLattes = intNumLattes + 1
        curTotalExpenses = curTotalExpenses + curLattePrice
    Wend

    Debug.Print intNumLattes
    MsgBox "You can purchase " & intNumLattes & " lattes.", _
        vbOkOnly, "Total Lattes"
End Sub                                                    

If you have $350 to spend on lattes, the While...Wend loop will run 100 times. You do not want to have to press F8 to step through the loop that many times. Thankfully, you have other options. If you know that the loop is producing correct data, you can place your cursor in the Debug.Print intNumLattes line and press Ctrl+F8 to invoke the Run to Curser. Pressing Ctrl+F8, will cause your procedure to run until it reaches the Debug.Print line; at that point, it will halt and the line will be highlighted. You can then press F8 to step through and execute just the highlighted line of code or press F5 to continue execution until the end of the procedure.

 
Others
 
- Microsoft Access 2010 : TESTING AND DEBUGGING VBA CODE (part 2) - The Debug.Assert Statement, Breakpoints, Stepping through Code
- Microsoft Access 2010 : TESTING AND DEBUGGING VBA CODE (part 1) - Immediate Window, The Debug.Print Statement
- Microsoft Access 2010 : Using the VBA Editor - ANATOMY OF THE VBA EDITOR, USING THE OBJECT BROWSER
- Microsoft Visio 2010 : Connecting Shapes - Understanding Visio Connectors (part 2) - Connecting to Shapes versus Points on Shapes
- Microsoft Visio 2010 : Connecting Shapes - Understanding Visio Connectors (part 1) - Connecting Basics
- Microsoft PowerPoint 2010 : Working with Animation and Transitions - Setting Slide Transitions
- Microsoft PowerPoint 2010 : Finalizing Your Slide Show - Rehearsing Your Presentation
- Microsoft Project 2010 : Creating Master Schedules with Inserted Projects - Reporting and Analyzing Across Projects
- Microsoft Project 2010 : Creating Master Schedules with Inserted Projects - Critical Path Across Projects
- Microsoft Excel 2010 : Linking a Cell to Smart Art
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us