Lab 7.3 - Phone Directory

Guy with Phone

Phone directories are everywhere, and with the advent of cell phones with auto-dial, it's harder than ever to keep track of people's numbers. Seriously, when was the last time you actually dialed your friend's number? There's got to be a better way, right?

There is. In this lab, we're going to keep track of names and numbers in a type of data structure called a parallel array. There will be two dynamic arrays, one for the names and one for the numbers. The indicies of each array will match. So the name in strName(3) goes with the number in strNumber(3).

You'll need a Form, a ListBox to display the array, two TextBoxes (one for name and one for number), and three Buttons: Add, Find, and Delete.

When a Button is clicked, the action that the program takes is determined by the Button clicked:

  • "Add" will increase the size of each array by one and add the name and phone number to the appropriate arrays.
  • "Find" will take the name from the name text box, search through the name array, and then either put the phone number for that name in the text box for number or the string "Name Not Found" if the name is not in the array.
  • "Delete" will search through the array for the name in the name text box, find the name being looked for, and copy down the names and numbers from elements with indicies higher than the found name and number by one space (the same way that we shifted the numbers in the random numbers lab) and then reduce the size of the array by one. If the name isn't found, the user should be told.

    HINTS: Use a string for the numbers as well as the names, so you can use characters like () and - in your phone numbers. Remember that the indicies in each array match, so you can reuse the index or size from one in the other.

    It wouldn't hurt to have an "are you sure" MsgBox pop up first. When the second (usually blank) argumet of a MsgBox call is 1, then the box that pops up has two buttons: OK and Cancel. The MsgBox function returns 1 when you click OK and 2 when you click Cancel.

    As always, design a useful and proper interface, including tab order and access keys.