Lab 12 - Files
For this project you may create your own interface or use the one provided
in the Shell folder on the Content tab in Angel. If you use the shell "make it your own" by changing colors, fonts, and/or rearrange
the layout.

This program will maintain a list file containing information about friends.
It will also display the contents of the file when the user requests it.
Form Load Event
-
Use an Inputbox to query the user for file name and location of the Friends file.
-
Open the file (output stream)
Note: If the program can not open the file because of user
input error it will die. This is normally unacceptable but since we have not
covered error handling we will not address this problem at this time. Just be
sure to enter valid path and filename, including a .txt extension.
Hints:
-
To create the shell for the Load event for the form double click on any
blank space of the form
OR
-
choose
(Form Events) from the Object List Box

and then the Load
Event from the Event List Box

-
You can take advantage of the DefaultResponse argument of the InputBox
function to populate the
Textbox portion of the InputBox( ) with the file name so that you do not have
to type it every time you run your program.
………InputBox( “prompt”,”title”, “E:\Friends.txt”)
-
Since you will be either creating a new file or adding to an existing
file set the Append argument to True when you open the file.
-
The variable that you use to store the file’s path and name must be
declared at Class Level (in the declaration section) so the file name and
path entered in the InputBox( ) is available no matter which procedure is
opening the file.
-
Since you will be referencing the StreamWriter object in more than one
procedure (Form's Load when opening the file, Button's Click event when
writing to the file, and the Form's Closed event when closing the file)
the StreamWriter object should be declared at Class level.
Add Friend
Will write the information provided via
textboxes to the Friend text file.
-
The first and last name are required fields
-
In addition to the five values provided by the user add a
number as the first field in the record to act as key field. For now do not
worry about the key field being unique. Create a Class level variable to
hold the key field value and increment it each time you write a new record
to the file. The number will start over each time you execute the program.
We will add code to make the value unique later.
-
Each time new data is written to the file clear all the
textboxes and return focus to the first name textbox.
An example of the resulting file. Note: Blank lines indicate
field values not provided by the user.

Hints:
-
Use a separate WriteLine statement for each data value.
-
Check the file frequently to verify the information is being written to
the file.
-
IMPORTANT: You must Close the file before
checking it. Since the StreamWriter object "buffers" output some data will
not actually be written to the file until you Close it. This means that if
you check the file when the program is still running data may be missing.
Display All
Will read the Friend file and display the
information for all the friends on the form, one friend per line.
-
Display the key field value only if the user checks the appropriate
checkbox.
-
Align each field value in columns
-
Provide column headings

Hints:
-
Since a file may not be open for reading at the same time
it is open for writing you will need to Close the file before you can open
it for reading.
-
Use the StreamReader's Peek method to recgonize when you
have reached the end of the Friends file.
-
Use the PadRight string method to create columns.
-
Use ControlChars.NewLine to report each friend on a
separate line.
-
After displaying all the friends you will need to Close
the file and reopen it for writing so that you can continue to add new
friends to the file.
Form FormClosed Event
-
Close all open files (Streams)
Hints:
-
To create the shell for the FormClosed event for the
form choose (Form Events) from the Object List
Box and then the FormClosed Event from the
Event List Box