My IPT students (young programmers) are constructing an address book using text files as their data file. One of the ways to sort through it is to use Listboxes (particularly since they haven’t discovered arrays yet).
Now, I’m not about to give them the answers for their project, but, if they use a combination of the following 4 techniques, they can construct a working address book which allows them to read from a data file, add new contacts, edit contacts, remove contacts and keep their data up to date.
Example 1: Adding an item to a listbox.
This will also demonstrate how to read from a file into the listbox, display an item’s text in a text box and append the new item to the end of the data file (append means put on the end).
Zip file containing project: http://bit.ly/listbox1
Example 2: Inserting an item into a list
Now this sample project demonstrates how to insert an item at a select place (HINT: it’s the selectedindex… or you could just make up an index… which is an integer).
It will also show:
- How to read from a data file into a list
- how to display information from the list in a text box
- how to OUTPUT the list to the data file. NB: this is the whole list. Output overwrites the entire data file. This is different from append which simply places it at the end of the string data.
Zip file containing project: http://bit.ly/listbox2
Example 3: deleting an item from the list
This project demonstrates how to delete an item from the listbox. It will also show how to OUTPUT the updated list out to the data file (like example 2). NB: used in conjunction with the earlier examples, you can edit the data (think about it… order is important in this one)
Video: not yet available
Zip file containing project: http://bit.ly/listbox3
Example 4: multiple listboxes
This is the big one. It shows how to read from a single data file into multiple listboxes.
It also shows:
- how to synchronise the listboxes when the first list is clicked in
- how to display each list’s selected item’s info in labels
- how to iterate through lists (for i = … )
Zip file containing project: http://bit.ly/listbox4
Now – using all of these together, you should be able to construct the address book. Even if you’re not in my IPT class – it’s worth a try… it’s fun!