Results 1 to 2 of 2

Thread: Using Constructor to read a file...

  1. #1

    Thread Starter
    New Member skiman62's Avatar
    Join Date
    Nov 2003
    Posts
    12

    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:
    1. Private Sub mmuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
    2.  
    3.         Dim ofdMain As New OpenFileDialog
    4.         Dim dlgResult As DialogResult
    5.         dlgResult = ofdMain.ShowDialog()
    6.         f() = New UNR.Employees.EmployeeList(ofdMain.FileName)
    7.  
    8.  End Sub
    This is the click even that needs to lead to this.....
    VB Code:
    1. Public Sub New(ByVal pstrFileName As String)
    2.             Dim pstrCurrent As String
    3.             Dim pstrFields() As String
    4.             Dim pstrDelimiter() As Char = {ToChar(",")}
    5.             Dim psrdcurrent As New System.IO.StreamReader(pstrFileName)
    6.  
    7.             pstrCurrent = psrdcurrent.ReadLine()
    8.             Do Until pstrCurrent = Nothing
    9.                 Dim recNew As New Employee
    10.                 pstrFields = pstrCurrent.Split(pstrDelimiter)
    11.                 recNew.ID = ToInt32(pstrFields(0))
    12.                 recNew.LastName = pstrFields(1)
    13.                 recNew.FirstName = pstrFields(2)
    14.                 recNew.SSN = pstrFields(3)
    15.                 recNew.HoursWorked = ToDouble(pstrFields(4))
    16.                 recNew.HourlyWage = ToDouble(pstrFields(5))
    17.                 recNew.Age = ToInt32(pstrFields(6))
    18.                 alEmployee.Add(recNew)
    19.                 pstrCurrent = psrdcurrent.ReadLine()
    20.             Loop
    21.             psrdcurrent.Close()
    22.             mintCurrent = 0
    23.  
    24.         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!!
    "There are no stupid answers...only stupid questions. Or is it the other way around....hummm...."

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    New Constructors do not return data.

    If you wish to use
    VB Code:
    1. f() = New UNR.Employees.EmployeeList(ofdMain.FileName)

    you will have to use a seperate function to handle this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width