karmaChrome
New member
- Joined
- Mar 11, 2006
- Messages
- 1
- Programming Experience
- Beginner
Hello-
I have an assignment that is to read two files and distribute each file into it's respective array - it looks as though this is being accomplished. When an "employee number" in a combo box is selected, the array members that correspond to that number are listed in several list boxes - which it does...sort of...Only when selecting the final entry (number "900") do the list boxes receive entries:the entire array! Why would this be occuring?
Any help for a tired student will be greatly appreciated...thanks!
I have an assignment that is to read two files and distribute each file into it's respective array - it looks as though this is being accomplished. When an "employee number" in a combo box is selected, the array members that correspond to that number are listed in several list boxes - which it does...sort of...Only when selecting the final entry (number "900") do the list boxes receive entries:the entire array! Why would this be occuring?
Any help for a tired student will be greatly appreciated...thanks!
VB.NET:
Option Explicit On
Option Strict On
Imports System.Convert
Public Structure sEmployee
Public IDNumber As String
Public Name As String
Public Address As String
Public SSN As String
End Structure
Public Structure sPayroll
Public IDNumber As String
Public PayrollDate As DateTime
Public GrossPay As Single
Public Taxes As Single
Public FICA As Single
Public NetPay As Single
End Structure
Public Class frmMain
Inherits System.Windows.Forms.Form
Private Sub btnOpenInputFiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenInputFiles.Click
Dim psrdEmployee As System.IO.StreamReader
Dim psrdPayroll As System.IO.StreamReader
Dim pintCount, pintpayroll As Integer
Dim pstrEmployeeLine, pstrPayrollLine As String
Dim pstrEmployeeFields(), pstrPayrollFields() As String
Dim pchrDelimiter() As Char = {ToChar(",")}
Try
ofdEmployee.ShowDialog()
psrdEmployee = New System.IO.StreamReader(ofdEmployee.FileName)
pstrEmployeeLine = psrdEmployee.ReadLine()
Do Until pstrEmployeeLine = Nothing
ReDim Preserve Employee(pintCount)
pstrEmployeeFields = pstrEmployeeLine.Split(pchrDelimiter)
Employee(pintCount).IDNumber = pstrEmployeeFields(0)
Employee(pintCount).Name = pstrEmployeeFields(1)
Employee(pintCount).Address = pstrEmployeeFields(2)
Employee(pintCount).SSN = pstrEmployeeFields(3)
pintCount += 1
pstrEmployeeLine = psrdEmployee.ReadLine
Loop
psrdEmployee.Close()
ofdPayroll.ShowDialog()
psrdPayroll = New System.IO.StreamReader(ofdPayroll.FileName)
pstrPayrollLine = psrdPayroll.ReadLine()
Do Until pstrPayrollLine = Nothing
ReDim Preserve Payroll(pintpayroll)
pstrPayrollFields = pstrPayrollLine.Split(pchrDelimiter)
Payroll(pintpayroll).IDNumber = pstrEmployeeFields(0)
Payroll(pintpayroll).PayrollDate = ToDateTime(pstrPayrollFields(1))
Payroll(pintpayroll).GrossPay = ToSingle(pstrPayrollFields(2))
Payroll(pintpayroll).Taxes = ToSingle(pstrPayrollFields(3))
Payroll(pintpayroll).FICA = ToSingle(pstrPayrollFields(4))
Payroll(pintpayroll).NetPay = ToSingle(pstrPayrollFields(5))
pintpayroll += 1
pstrPayrollLine = psrdPayroll.ReadLine
Loop
psrdPayroll.Close()
For pintCount = 0 To Employee.GetUpperBound(0)
cboEmployee.Items.Add(Employee(pintCount).IDNumber)
Next
For pintCount = cboEmployee.Items.Count - 1 To 1 Step -1
If cboEmployee.Items(pintCount - 1).ToString = _
cboEmployee.Items(pintCount).ToString Then
cboEmployee.Items.RemoveAt(pintCount)
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK)
End Try
End Sub
Private Sub cboEmployee_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboEmployee.SelectedIndexChanged
Dim pintcount, pintpayroll As Integer
Dim pstrEmployee As sEmployee
Dim pstrPayroll As sPayroll
For pintcount = 0 To Employee.GetUpperBound(0)
If cboEmployee.Text = Employee(pintcount).IDNumber Then
pstrEmployee = Employee(pintcount)
lblName.Text = Employee(pintcount).Name
lblAddress.Text = Employee(pintcount).Address
lblSSN.Text = Employee(pintcount).SSN
For pintpayroll = 0 To Payroll.GetUpperBound(0)
If Employee(pintcount).IDNumber = Payroll(pintpayroll).IDNumber Then
lstDate.Items.Add(Payroll(pintpayroll).PayrollDate.ToShortDateString)
lstGross.Items.Add(Payroll(pintpayroll).GrossPay.ToString)
lstWithholding.Items.Add(Payroll(pintpayroll).Taxes.ToString)
lstFICA.Items.Add(Payroll(pintpayroll).FICA.ToString)
lstNet.Items.Add(Payroll(pintpayroll).NetPay.ToString)
End If
Next
End If
Next
End Sub
End Class