Using Constructor to read a file...
Hello all! I am trying to read a file using a constructor. Here is what I have thus far...
Private f() As UNR.Employees.Employee
VB Code:
Private Sub mmuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
Dim ofdMain As New OpenFileDialog
Dim dlgResult As DialogResult
dlgResult = ofdMain.ShowDialog()
f() = New UNR.Employees.EmployeeList(ofdMain.FileName)
End Sub
This is the click even that needs to lead to this.....
VB Code:
Public Sub New(ByVal pstrFileName As String)
Dim pstrCurrent As String
Dim pstrFields() As String
Dim pstrDelimiter() As Char = {ToChar(",")}
Dim psrdcurrent As New System.IO.StreamReader(pstrFileName)
pstrCurrent = psrdcurrent.ReadLine()
Do Until pstrCurrent = Nothing
Dim recNew As New Employee
pstrFields = pstrCurrent.Split(pstrDelimiter)
recNew.ID = ToInt32(pstrFields(0))
recNew.LastName = pstrFields(1)
recNew.FirstName = pstrFields(2)
recNew.SSN = pstrFields(3)
recNew.HoursWorked = ToDouble(pstrFields(4))
recNew.HourlyWage = ToDouble(pstrFields(5))
recNew.Age = ToInt32(pstrFields(6))
alEmployee.Add(recNew)
pstrCurrent = psrdcurrent.ReadLine()
Loop
psrdcurrent.Close()
mintCurrent = 0
End Sub
I am having trouble getting the file that I open to "transfer" over to the constructor to read it into an array. Thanks in advance!!