When your application doesn't produce correct results, browse through the code and try to find statements that may have caused the problem. Set breakpoints at these statements and restart the application.
When the program halts, test the values of important variables and properties. Use the Immediate window to examine variables and expressions.
To track down a difficult bug
First and foremost, make a backup. This is the point at which even experienced programmers frequently lose many hours of work. When you experiment, it is far too easy to accidentally overwrite or delete necessary sections of code.
Use the debugging facilities built into the integrated development environment. Attempt to identify the line or lines of code generating the error. Isolate the code. If you can isolate the problem to one block of code, try to reproduce the same problem with this block of code separated from the rest of your program. Select the code, copy it, start a new project, paste the code into the new project, run the new project, and see if the error still occurs.
Create a log file. If you cannot isolate the code or if the problem is erratic or if the problem only happens when compiled, then the debugging facility of the integrated development environment will be less effective. In these situations you can create a log file that records the activity of your program. This will allow you to progressively isolate the location of the suspect code.
Simplify the problem. If possible, remove any third-party components from your project. Eliminate any code that does not seem to relate to the problem.
Reduce the search space. If you cannot resolve the problem with any of the above methods, then it is time to eliminate all other causes from the problem search space. Copy your Autoexec.bat and Config.sys files to backup files. Comment out any and all drivers and programs from these two files that are not absolutely essential to running your program under Windows. Change your Windows video driver to the standard Windows VGA driver. Shut down Windows and reboot your machine. This will eliminate the possibility that there is some other program or driver that is interfering with your program.
If you cannot locate a solution and are unable to isolate or resolve the problem with any of these methods, it's time to look for help. See "Technical Support" in the documentation.