For our last OOP project of the semester we got to play with File I/O again. This time our goal was to make an address book. Instead of working with a console application we were to work with forms to give it a GUI. The picture below is how mine turned out:
You're missing out on the welcome screen but trust me it is amazing (if you like console font text, of which there is plenty). The program reads a list of contacts and their various information from a text file as soon as you load it up and uses StreamReader again to store the information so that the program can actually use it. Similar try and catch logic is in play as it was in my Mario Trivia Game from last week, just in case something goes wrong with the text file (for example, if it was not there or named the wrong thing). After clicking the start button the user is shown the window above (minus the code underneath it). The Contacts ComboBox (the drop down menu) is empty at first, but clicking on the arrow gives the user the last names of all the contacts in alphabetical order. Selecting the last name of the contact then brings up all the information, such as what you see for Susie Susanson of San Francisco (I'm mostly sure she is not real, and if she is I hope she goes elsewhere for her email soon).
Mostly all of the GUI stuff was pretty easy, we have done it before when we made a Farmer Game a few weeks ago (blog posting of that as a "Blast from the past": forthcoming!) and while I was fumbling around at first the knowledge of how to set things up came back fast. It's especially handy to have your old programs to look at whenever something stumps you a bit. The other thing that is super handy to have is the MSDN library:
The code above was found by my tutor and myself as I wanted to be able to sort by last name alphabetically without screwing up the index. It turned out there was a method already built to do this, aptly named Sort. It is there to sort Lists for you and was a really great find. There have been many times in both semesters where I have gone to the MSDN library to see how things work, either on my own or with a helpful reminder from my friend. I did run into one bug this project where I accidentally had a couple blank lines in my text file, and StreamReader found them and the whole program got very angry. But some breakpoint debugging led me to the answer, though I had help on this one too, I could see that there was extra incomplete information, but could not fathom the source on my own. It is something I will be very aware of in the future, and it worked out well enough in the present as I got a really good grade on the program. All that is left for the semester is compiling everything I have made in to my existing portfolio from last semester and the final. After that, it's Advanced OOP and I'm sure it will be a blast!


No comments:
Post a Comment