1. Home
  2. Computing & Technology
  3. Visual Basic
Using Bookmarks and the Task List
The Music Trivia Program Reconsidered!
 Topics
  From The Lesson
The Music Trivia program
 
Microsoft's gotdotnet site
 
The .NET Framework
TimeZone class

 

One of my personal favorite "debugging" features is both new to VB.NET and also one missed by the book, however. So the remainder of this lesson will concentrate on using the Find and Mark features. I find them to be as useful any any of the other features!

Let's reconsider the Music Trivia program that we wrote to extend the book in Chapter 3. This was also where I introduced the Debug.Write statement to give you an initial look at debugging techniques.

One of the things that is, welllll .... not actually 'wrong' but certainly confusing, about the Music Trivia program is the proliferation of 'buttons' in the program source. There are radio buttons, command buttons and debug statements about buttons. You could start to see buttons before your eyes in trying to understand what the program is doing. I mention this fault in discussing the program in the lesson. Let's see what we can do about it.

To begin to understand what's happening, we need a way to 'see' lines of code that we're interested in without just visually scanning for them. Let's assume that you want to highlight the second If statement in the Button1_Click subroutine where the value of RadioButton1.Checked property is tested. The answer is to "bookmark" the line.

Make sure that the "Text Editor" toolbar is selected. (Right click in the toolbar area to see the list of tool bars that you can select.) Then click anywhere in the line you're interested in and toggle the bookmark on with the flag icon. This visual clue (it doesn't change the program at all) is saved with the program source so you can close and reopen the program and it will still be there. This way, VB.NET will help you remember important statements that you want to be able to find again in the code.

mark menu

Suppose you want ALL the statements that contain Button1 (but not RadioButton1) to be marked so you can see what the program does with it. VB.NET will find them all for you! Just select the Find option from the Edit and then Find and Replace menu items. Enter Button1 in the Find what text box, select the Match whole word checkbox, and then click the Mark All button. This will tell you at a glance that Button1 is in exactly three statements in the program and should give you a very good idea what it does. Note that Button1_Click is not marked but Button1.Click is marked. That's because Button1_Click is a single name but Button1.Click is two names connected with the 'dot' operator. It makes a big difference in VB.NET!

marking

The first rule of debugging is to make changes ONLY when you know what you're doing. RadioButton is in a number of places in the program. (See if you can mark them all in your copy of the code!)

Suppose you decide that you're going to change the Enabled property to False to make sure that a player doesn't click a different answer after selecting one in the middle of a game. You might decide what change to make to the code, but then you should examine all the places in the code where RadioButton is used to make sure that something unexpected doesn't happen. So ... how do you 'remember' the change you had in mind while you think about the other parts of the program? Answer: Create a Named Bookmark - also known as a Task List Shortcut.

Open the Task List window (not a requirement, but it helps you to see what's happening) and click in the line where you want to add the Named Bookmark. Then select Add Task List Shortcut from the Edit and then Bookmarks menu item.

Once a task has been added, you can check them off as complete, sort them by priority, give them unique names and generally manage your programming. If you're on a programming team, you can use this technique to coordinate the team effort. The bottom line is that it's a great way to accomplish Rule One of debugging.

tasks

Next page >>>   Assignment from the Chapter 7 lesson
The Time Zone Clock

Page 1, 2, 3, 4

Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.