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.
Breakpoints - Stops execution at a specific line of code.
MsgBox - Displays popup messages and values to the screen.
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.
Immediate Window - Displaying variables and executing lines of code.
Debug.Print - Displays messages and values in the Immediate Window.
Quick Info - provides the syntax for a variable, function, method or procedure based n the location of your pointer. Select the expression and press (Shift + F9)
Parameter Info - Shows info about the parameters of the function in which the pointer is located
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.
You should include a gbDEBUG flag to be able to include additional debugging lines in your code.
Be able to switch loggin on and off easily.
Additional debugging code should be added when necessary. This can be flagged either using the global dbDEBUG_MODE constant or by placing debug.txt in the same folder
Be able to switch on debugging in textfile - send it to a textfile so it can be sent on to support.
Have a choice of different logging levels (high, medium, low)