Lab 13 - Arrays
For this project you will modify Lab 12 to read the entire contents of the Friend file into memory when the program loads.
-
-
When a new friend is added the data for that friend will be stored in the first available elements of the
parallel arrays.
-
When the user clicks a save button the data stored in the arrays will be written out to permanent storage in the form of a
comma delimited file.
-
If the friend data has been changed (new friend) but has not been saved when the user ends the program the user will be given an opportunity to save or not save the additions.
The Form Load Event
-
Use an Inputbox( ) to query the user for the file name and location of the Friends file.
-
If the file exists open the file as an
input stream and read
all the data into arrays in memory.
-
Do nothing if the file does not exist
Hints:
-
Since we are changing the structure of the Friend file you will
eventually need to delete any previous Friend files and begin a new friend
file from scratch.
-
Use the Exists method of the File object to see if the Friend file already exists.
If IO.File.Exists(strFileName)
Then......
-
-
Initialize the next key field value (to be assigned to the next friend added) using the value of the last key stored in the file.
Add Friend
Save the information provided via
textboxes in the next available elements of the
parallel arrays.
Hints:
-
You will need to keep track of the next available location in the arrays. You can do so by using a
class level variable.
-
The same index will used to reference all of the arrays.
Save Friends
Hints:
-
You will have to add a button to the form for this task. To maintain the same size, font, and color as the existing command buttons copy one of the buttons (right-click, choose copy, then right-click, choose paste), name it, and change the text property.
-
Create a sub procedure that saves the friend data. You will use the same procedure when the program is closed.
-
Open the file via a StreamWriter object (Append parameter will be omitted or set to False)
-
-
Be sure to write only the friend data to the file. Do not write empty records.
An example of the resulting file.

Note: consecutive commas indicate
field values not provided by the user.
Display All
Work through the parallel arrays displaying the
information for all the friends on the form, one friend per line.
Hints:
-
You will NOT be accessing any files in this procedure
Form FormClosed Event
If the file has not been saved since the last change ask the user if they want to save the changes.
If the user wishes to save the changes call the Save
procedure.
Hints:
-
Use a class level Boolean variable to keep track of whether the data has been changed / saved. You might call it blnIsDirty.
-
Use the MsgBox Function to ask the user if they want to save the file.
-
Be sure to turn the Boolean variable Off (false) and On (true) at
appropriate times.