Partager via


Visual Basic Concepts

Avoiding Bugs

There are several ways to avoid creating bugs in your applications:

  • Design your applications carefully by writing down the relevant events and the way your code will respond to each one. Give each event procedure and each general procedure a specific, well-defined purpose.

  • Include numerous comments. As you go back and analyze your code, you'll understand it much better if you state the purpose of each procedure in comments.

  • Explicitly reference objects whenever possible. Declare objects as they are listed in the Classes/Modules box in the Object Browser, rather than using a Variant or the generic Object data types.

  • Develop a consistent naming scheme for the variables and objects in your application. For more information, see "Coding Conventions."

  • One of the most common sources of errors is incorrectly typing a variable name or confusing one control with another. You can use Option Explicit to avoid misspelling variable names. For more information on requiring explicit variable declaration, see "Introducing Variables, Constants, and Data Types" in "Programming Fundamentals."