Chapter 12. Debugging Code

A bug is a programming error that makes a program fail to produce the correct result. The program might crash, display incorrect data, or do something completely unexpected such as delete the wrong file.

In this lesson you learn how to use the excellent debugging tools provided by Visual Studio's IDE to find bugs in Visual Basic. You learn about different kinds of bugs and you get to practice debugging techniques on some buggy examples that you can download from the book's web site.

DEFERRED TECHNIQUES

Unfortunately, at this point in the book you don't know enough about writing code to be able to understand and fix certain kinds of bugs. For example, a program crashes if it tries to access an array entry that is outside of the array, but you won't learn about arrays until Lesson 16.

So why does this lesson cover debugging when you don't even know all of what can cause bugs or the techniques that you need to fix certain kinds of bugs? It makes sense for two reasons.

First, the previous lesson was the first part of the book in which you were likely to encounter bugs. Whenever I teach beginning programming, students start seeing bugs as soon as they write code that performs calculations like those covered in Lesson 11. These kinds of bugs are easy to fix if you know just a little bit about debugging but can be extremely frustrating if you don't.

Second, it turns out that you don't need to know more advanced techniques to learn simple debugging. Once you learn how ...

Get Stephens' Visual Basic® Programming 24-Hour Trainer now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.