Common Sources of Errors

Studies show that developers tend to make the same types of mistakes, no matter what language they are using or what program they are writing. The following table lists common problems that lead to bugs and suggestions for avoiding them.

Common Sources of Programming Errors

Problem Suggestion for avoiding
Wrong data type in a variable, such as expecting a text value from a property instead of a number.
  • Explicitly declare variables, even if not required. For example, in VBScript, use the Dim statement; in JScript, use the var statement.

  • Use naming conventions to help you remember variable types, such as txtName for a string, fDone for a flag, and intCounter for a number (integer).
Not understanding what objects are available in a given context; for example, attempting to set properties for a Session object in a client script, or attempting to use the Internet Explorer object model in a script running on a different browser.
  • Be aware what objects your scripts have access to and what the scope or context is of an object. Be aware that objects (such as ASP built-in objects) are not an inherent part of a language such as VBScript; instead, they are part of the environment in which a script is running.
Not understanding a function or procedure; calling the incorrect function.
  • Double-check that the function you are calling performs the task you want it to.
Incorrect arguments for functions; arguments passed in the wrong order; not understanding what values a function or procedure returns.
  • Check syntax for functions whenever using them.

  • Avoid relying on default argument values.
Not understanding the meaning of a value, such as whether the values passed to a Move method represent pixels or another unit, or whether they are absolute or relative.
  • Double-check argument definitions for all functions and methods.
Not understanding a data structure, such as the object model for a browser, or trivial misunderstandings such as assuming that an array index begins with 1 instead of 0 or vice-versa.
  • Check documentation for information about structure.
Typographic errors, such as misspelling a variable name or keyword, or forgetting to close a bracket.
  • Use consistent names to help avoid confusion.

  • Type the closing portion of a statement as soon as you type the opening portion. For example, when you are creating a server script, as soon as you type <%, type %>, and then fill in the statements between the delimiters.
Unexpected data, such as a user typing in a string when prompted for a number, or a number value outside the bounds of what the program can use.
  • Anticipate errors introduced by users and create error-handling routines.
Not understanding language conventions, such as using the wrong type of quotation marks to enclose literals. This is an easy mistake to make when switching between languages such as between Visual Basic and SQL.
  • Familiarize yourself with the operators and conventions of the language you are using.


© 1997 by Microsoft Corporation. All rights reserved.