I have a program that reads data from 2 sequential data files. One file is called Employee and the other is Payroll. The form contains a open files button that allows the user to open both files. Once chosen the program reads the files and puts the data in the appropriate structure item. It also should load the employee ids from the employee file into the combobox which is on the form. I cannot seem to get the data to pull in from the structure and be added to the combobox. Any help would be appreciated. Here is my code and a sample of the employee file.
Main form code:
CODE
Imports System.Windows.Forms.OpenFileDialog
Public Class empPayrollForm
Private CurrentEmployeeList As EmployeeList
Private CurrentPayrollList As PayrollList
Private CurrentRecord As Integer
Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
' closes application
Me.Close()
End Sub
Private Sub openFileButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles openFileButton.Click
Dim payrollResult As DialogResult
Dim employeeResult As DialogResult
OpenEmpFileDialog.Title = "Please Select Master Employee File"
OpenEmpFileDialog.Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
employeeResult = OpenEmpFileDialog.ShowDialog
If employeeResult = Windows.Forms.DialogResult.OK Then
CurrentEmployeeList = New EmployeeList(OpenEmpFileDialog.FileName)
selEmpComboBox.Items.AddRange(Employee.empId)
End If
OpenPayrollFileDialog.Title = "Please Select Master Payroll File"
payrollResult = OpenPayrollFileDialog.ShowDialog
If payrollResult = Windows.Forms.DialogResult.OK Then
CurrentPayrollList = New PayrollList(OpenPayrollFileDialog.FileName)
End If
End Sub
Module created containing structure employee and employeelist class as per project requirements that I use module-level dynamic arrays. I may be incorrectly using as module for this as I'm relatively new and when I saw module-level thought module:
CODE
Option Explicit On
Option Strict On
Imports System.IO
Imports System.Convert
Module Employee
Public Structure Employee
Public empId As Integer
Public empName As String
Public empAddress As String
Public empSSN As String
End Structure
Public Class EmployeeList
Private CurrentReader As StreamReader
Private CurrentWriter As StreamWriter
Private CurrentList(0) As Employee
Private RecordCount As Integer
Public Sub New(ByVal argFile As String)
CurrentReader = New StreamReader(argFile)
Call ReadEmployees(argFile)
CurrentReader.Close()
End Sub
Private Sub ReadEmployees(ByVal argFile As String)
Dim CurrentEmployee As Employee
Dim Fields() As String
Dim CurrentRecord As String
Dim DelimiterChars() As Char = {ToChar(",")}
CurrentRecord = CurrentReader.ReadLine()
Do Until CurrentRecord Is Nothing
Fields = CurrentRecord.Split(DelimiterChars)
With CurrentEmployee
.empId = CInt(Fields(0))
.empName = Fields(1)
.empAddress = Fields(2)
.empSSN = Fields(3)
End With
ReDim Preserve CurrentList(RecordCount)
CurrentList(RecordCount) = CurrentEmployee
CurrentRecord = CurrentReader.ReadLine()
RecordCount += 1
Loop
RecordCount += 1
End Sub
End Class
End Module
Thanks for any tips on how to do this that you guys can provide me to push me in the right direction