Debugging Checklist

See Also1ANBOTU

There are three types of errors you may encounter as you run your application:

         Compile errorsoccur as a result of code that is incorrectly constructed.  You may have an incorrectly matched control structure, such as a Next statement without a corresponding For statement, or programming mistakes that violate the rules of Basic, such as a misspelled word, a missing separator, or a type mismatch.

     Compile errors include syntax errors, which are errors in the grammar or punctuation recognized by Visual Basic.  Examples of syntax errors include passing an incorrect number of arguments to an intrinsic function or forgetting to match parentheses.

         Run-time errorsoccur after the application starts to execute.  Examples of run-time errors include attempting an illegal operation, such as writing to a file that doesn't exist, or dividing by zero.

         Logical errorsthe program doesn't perform as intended, and produces incorrect results.

 

Debugging is a process by which you find and resolve errors in your code.  To debug code in Visual Basic, consider the ideas suggested below.  These techniques can also be applied in different sequences.

   1. Print the code, if you find it easier to read code on paper instead of online.

   2. Run the application to find trouble spots:

      From the Run menu, choose Start (F5) to begin running the application.

      Run until an error stops execution, or halt execution manually when you suspect an error by choosing Break from the Run menu (Ctrl+Break).

      Resolve all compile errors and run-time errors.

      From the Run menu, choose Continue (F5) to continue running the application.

   3. Use debugging tools and techniques to isolate bugs and to monitor code flow:

      Set breakpointsBMA26TM to halt execution at certain points to look for problems such as incorrect variable types, mixups in variable names, flaws in logical comparisons, endless loops, garbled output, problems with arrays, and so on.  You can also set breakpoints to monitor code flow or examine information in the current state.

      Add a watch expression1Z5654F at design time or while in break mode to allow you to monitor the value of a particular expression as your code execution progresses.

      Single step (F8) or procedure step (Shift+F8) through your code to trace132XRCU through the application as it's running.

      Use the Debug window1XHHA8K to test individual lines of code or procedures, or to change values.

      Enter break mode and choose Calls (Ctrl+L) from the Debug window to see where your code is currently executing and trace the path showing how it got there.

   4. Try out bug fixes and then make edits:

      Test individual lines of new or debugged code in the Debug window.

      Search and replace7N96V2 code for all occurrences of an error, checking other procedures, forms, or modules with related code.

      From the Run menu, choose Restart (Shift+F5) to reset application variables and properties and restart the application from the beginning.


See Also

Help:

Continuing ExecutionCZRW3ZU

Ending Execution4KTFWY

Finding a Procedure1CNGZXN

Guidelines for Entering and Editing Code5SZA0GX

Halting Execution11S25K

Restarting ExecutionF5EDVC

Starting Execution1AHX1VG

 

Learning Visual Basic

Debugging Your Application

 

Programmer's Guide:

Chapter 9, "Debugging"