Monitoring Data with Watch Expressions

As you debug your code, you might find that a problem occurs only when a certain variable or property assumes a particular value or range of values. Or you might learn that a calculation isn't producing the desired result. Many debugging problems aren't immediately traceable to a single statement, so you might need to observe the behavior of a variable or expression throughout a procedure.

You can monitor the value of a particular variable or expression in a watch expression. Visual Basic monitors watch expressions for you. In break mode, watch expressions appear in the Watch pane of the Debug window, where you can observe their values.

You can also direct a watch expression to enter break mode whenever the watched expression's value changes or becomes True. For example, instead of using Step Into to move through hundreds of loops, you can use a watch expression to put the code in break mode when a loop counter reaches a specific value. Or you can enter break mode each time a certain variable changes value.