Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 8 Debugging Visual Basic Programs 213



  1. If the form isn’t visible, display it now.


The Debug Test program prompts the user for his or her age. When the user
clicks the Test button, the program informs the user whether he or she is a teenager.
The program still has the problem with 13-year-olds that we identified earlier in the
chapter, however. You’ll open the Debug toolbar now and set a breakpoint to find the
problem.


  1. If the Debug toolbar isn’t visible, click the View menu, point to Toolbars, and then
    click Debug.
    The Debug toolbar appears below or to the right of the Standard toolbar.

  2. Click the Start Debugging button on the Standard toolbar.


The program runs and the Debug Test form opens.


  1. Remove the 0 from the Age text box, type 14 , and then click the Test button.


The program displays the message “You’re a teenager .” So far, the program displays
the correct result.


  1. Type 13 in the Age text box, and then click the Test button again.


The program displays the message “You’re not a teenager,” as shown in the following
screen shot:

This answer is incorrect, and you need to look at the program code to fix the problem.


  1. Click the Quit button on the form, and then open the Code Editor.

  2. Move the mouse pointer to the Margin Indicator bar (the gray bar just beyond the left
    margin of the Code Editor window), next to the statement Age = TextBox1.Text in the
    Button1_Click event procedure, and then click the bar to set a breakpoint.

Free download pdf