Application that reads two sequential files

Jynx

Active member
Joined
Oct 20, 2007
Messages
44
Programming Experience
Beginner
I am completely stuck. I have been at this for hours. Trying to teach myself with my books. This is the "hands on" project part of the book and I just can't figure it out.


You will create an application that reads two sequential files. The first file contains employee information. The second file contains payroll information for each employee. The record formats are listed below.

Employee File

*Employee ID - Integer
*Name - String
*Address - String
*SSN - String

Payroll File

*Employee ID - Integer
*Payroll Date - Date
*Gross Pay - Single
*Withholding Tax - Single
*FICA Tax - Single
*Net Pay - Single

1. Create the two structures and module-level dynamic arrays to store the data described above.
2. Create an Open Files button. In the Click event handler, write the code to open the employee and the payroll file and store the records in an array. As you read each employee records, write the statement to add the employee ID numbers to the combo box.
3. Write the code so that when the user clicks an item in the combo box, the employee name, address, and ssn appear in the labels below the combo box.
4. Write the code to display the payroll information for the selected employee ID.
5. Write the code to calculate the totals for each list box and display the values in labels below the list boxes.
 
Here's what I've gotten so far.

I've created 2 open file dialogs that read 2 text files into arrays.
The instructions make it sound like you open them both with 1 file dialog and it reads them into separate arrays (I don't know how to do that).

I've gotten it so it adds the Employee ID from the Employee Text file to the combo box.

When you click the employee ID from the combo box I've gotten it to populate all the labels.

Now I'm stuck. I don't know how to store all the information without using a collection. And I don't know what or why I'm supposed to be storing anything in structures. Maybe I've done everything wrong at this point.
 
Yea I think I may have done this all wrong. I think I'm supposed to store everything in the structure? I did this :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Result As DialogResult
ofdMain.Title = "Chapter 10 - Concept Lesson"
ofdMain.FileName = ""
Result = ofdMain.ShowDialog
If Result = Windows.Forms.DialogResult.OK Then
TextBox1.Text = ofdMain.FileName
End If

Dim nameFile As IO.StreamReader
Dim recordPointer As Integer
nameFile = New System.IO.StreamReader(TextBox1.Text)
Do Until nameFile.Peek = -1
Employee(recordPointer) = nameFile.ReadLine
recordPointer = recordPointer + 1
Loop
nameFile.Close()
ComboBox1.Items.Add(recordPointer - 2)
End Sub

I have a feeling I'm supposed to do this entirely different.

I then did this :

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Label1.Text = Employee(ComboBox1.SelectedItem - 1)
Label2.Text = Employee(ComboBox1.SelectedItem)
Label3.Text = Employee(ComboBox1.SelectedItem + 1)

Label4.Text = Payroll(ComboBox1.SelectedItem - 1)
Label5.Text = Payroll(ComboBox1.SelectedItem)
Label6.Text = Payroll(ComboBox1.SelectedItem + 1)
Label7.Text = Payroll(ComboBox1.SelectedItem + 2)
Label8.Text = Payroll(ComboBox1.SelectedItem + 3)
End Sub

This seems really messy and difficult. I think I'm going about this all wrong.
 
Back
Top