Microsoft Office Development and Consultancy
|VBA > Debugging > Getting Started||| Next >|
What is Debugging ?
You are always going to encounter errors in your code at some point and debugging will help you fix them.
There are four Different Types of Errors (design time, compile time, run time and logical)
Debugging is the process of identifying and fixing logical errors in your code since design time, compile time and run time errors are relatively easy to fix.
When people refer to bugs they are referring to logical errors.
A logical error is when your code does not perform its task correctly.
As your code becomes longer and more complicated you will appreciate the various debugging techniques.
These occur when the code appears to perform correctly but doesn’t actually produce the correct results.
When a logical error occurs you might see a run time error message popup up.
Logical errors can be classified into two types:
Wrong Datatype - expecting one datatype but somehow using a different datatype
Wrong Context -
The key to successful debugging is to perform a lot of real-life examples.
There are several different techniques you can use when debugging your code:
Auto Data Tips - Tooltips can display the current value when you hover over a variable with the mouse.
Debug.Print - Displays messages and values in the Immediate Window.
MsgBox - Displays popup messages and values to the screen.
Breakpoints - Stops execution at a specific line of code.
Immediate Window - Displaying variables and executing lines of code.
Watch Window - Displays the current value of variables as you step through the code.
Locals Window - Displays all the variables used in the current subroutine.
Things to Remember
If you happen to get yourself in a continuous loop with a dialog box displayed you can press (Ctrl + Break) and the MsgBox OK button at the same time.
The yellow arrow in the margin indicates that you are in Break mode
The "Stop" keyword will not be removed automatically when the Visual Basic Editor is closed.
|© Better Solutions Limited 15-Oct-2013||Top | Next >|