Chapter 8 Debugging Visual Basic Programs 215
Note You can also enter debugging mode in a Visual Basic program by placing the Stop
statement in your program code where you’d like to pause execution. This is an older, but
still reliable, method for entering debugging mode in a Visual Basic program.
- Place the pointer over the Age variable in the Code Editor.
Visual Studio displays the message “Age | 0” and a tiny pin icon appears next to the
value. While you’re in debugging mode, you can display the value of variables or
properties by simply holding the mouse pointer over the value in the program code.
Age currently holds a value of 0 because it hasn’t yet been filled by the TextBox1 text
box—that statement is the next statement the compiler will evaluate.
The pin icon is a new feature of Visual Studio 2010 that lets you pin the value of
an expression somewhere in the IDE while you are debugging. The pinned expression
is called a DataTip, and there are four commands on the Debug menu that are related
to this feature. Try using a DataTip now to watch the value of the Age variable.
- Click the pin icon to create a DataTip for the Age variable in the IDE.
- Hold the mouse over the DataTip that appears until three small buttons are displayed
next to the Age variable.
Your screen will look like the following:
Close
Agevariableanditscurrentvalue
Comment
Unpinfromsource
Until you remove this DataTip, it will display the value of the Age variable in the IDE.
If you click the Unpin From Source button, the Age variable will remain in its current
position in the IDE, even if you scroll the Code Editor window up or down. The
Comment button lets you add a descriptive comment to the Age variable, and the
Close button lets you remove the DataTip from the IDE.
- Click the Close button next to the DataTip to remove the Age variable and its value
of 0 for now.
As you can see, this is a handy way to watch variables change in a program as it runs,
and you should feel free to use DataTips whenever you debug your code. Before you
use them exclusively, however, experiment with some additional techniques in the
following steps.