How to determine the value of a variable


Often when you encounter an error, it is because a variable contains a value that you did not expect. It may be that a variable had a zero value and was then used in a division operation. Or a variable that was supposed to contain the name of a file somehow had a number stored in it. You can also see how a variable changes as the program runs. Watching the change in a variable's value, or the lack of a change, is one of the major factors in finding many program errors, including infinite loops.

To debug your program, you have to be able to determine the value of the variables that are used in the program at different points in the execution. Visual Basic provides you with three basic methods of checking the values of variables – the Watch window, the Locals window, and quick watches.