I'm stuck on my homework trying to deal with arrays of structs. The prof is terrible and just reads off slides from another prof and talks about his weekend. Heres what we have to do:

You have been hired as a programmer for Super Sales Company. You are being asked to write a sales report program. You should implement this program as an array of structures (set MAXARRAY = 39). There will not be 40 items, so you must keep track of how many items you have read in. The format for each line in the file commiss.dat contains an employee’s first name, last name, employee id number and the amount of sales for each weekday. This file is on VSpace in the resources. The following is a sample of the input file:

John Fredricks 102 70.00 90.00 104.00 305.00 408.00
Jane Williams 104 89.00 105.00 70.00 400.00 207.00
Scott Howard 103 100.00 100.00 100.00 100.00 100.00

You should create a report which prints out the employee’s name, id number, 5 daily sales, total sales and average sales. Here is a sample of the report you should create:

Super Sales Associate
Weekly Sales Report
Name ID Mon Tue Wed Thu Fri Total Average

John Fredricks 102 70.00 90.00 104.00 305.00 408.00 977.00 195.40
Jane Williams 104 89.00 105.00 70.00 400.00 207.00 871.00 174.20
Scott Howard 103 100.00 100.00 100.00 100.00 100.00 500.00 100.00
Fred Wilkes 105 189.00 207.00 306.00 99.00 203.00 1004.00 200.80


You may find it easier to create a location for the total and average columns within the struct definition. I know that there are other ways to do this program, but you must use an array of structs since your next assignment will be a modification of this assignment.

My problem is that I don't know how to make it so I can read string by string. I only know how to read by lines. So my codes something like:

Structure EmployeeInfo
        Dim FirstName As String
        Dim LastName As String
        Dim ID As String
        Dim Mon As Double
        Dim Tue As Double
        Dim Wed As Double
        Dim Thu As Double
        Dim Fri As Double
    End Structure

    Dim Data As EmployeeInfo
    Dim sr As IO.StreamReader = IO.File.OpenText("commiss.txt")

and then all I know how to do is Data.FristName = sr.ReadLine which stores the first line of data into Data.FirstName ....which I only want the first name.

So i'm wondering if theres something along the lines of Data.Firstname, Data.SecondName (etc) = sr.ReadLine? Something along the lines of the equivialnt to C++ like

infile >> Data.FirstName >> Data.SecondName >> Data.ID etc.

Thanks

So after some more research I've managed to find the Split Function.  However I'm getting an error in the red:


 Structure EmployeeInfo
        Dim FirstName() As String
        Dim LastName() As String
        Dim ID() As String
        Dim Mon() As Double
        Dim Tue() As Double
        Dim Wed() As Double
        Dim Thu() As Double
        Dim Fri() As Double
    End Structure
    Dim MAX_SIZE As Integer = 39
    Dim Data(MAX_SIZE) As EmployeeInfo
    Dim line As String
    Dim total As Double
    Dim fmtStr As String = "{0,-10}{1,10}{2,8}{3,8}{4,8}{5,8}{6,8}{7,8}{8,10}"

    Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        Dim i As Integer = -1
        Dim sr As IO.StreamReader = IO.File.OpenText("commiss.txt")
        PrintHeader()

        Do While (sr.Peek <> -1)
            i += 1
            line = (sr.ReadLine)
            Data(i).FirstName = line.Split(" "c)
            Data(i).ID = line.Split(" "c)
            Data(i).Mon = line.Split(" "c)
            Data(i).Tue = line.Split(" "c)
            Data(i).Wed = line.Split(" "c)
            Data(i).Thu = line.Split(" "c)
            Data(i).Fri = line.Split(" "c)

            total = Data(i).Mon + Data(i).Tue + Data(i).Wed + Data(i).Thu + Data(i).Fri

            lstDisplay.Items.Add(line)
        Loop
        
        'lstDisplay.Items.Add(Data.Tue)


    End Sub
    Sub PrintHeader()
        With lstDisplay.Items
            .Clear()
            .Add("                                     Super Sales Associate")
            .Add("                                      Weekly Sales Report")
            .Add("")
            .Add(String.Format(fmtStr, "Name", "ID", "Mon", "Tue", "Wed", "Thu", "Fri", "Total", "Average"))
            .Add(String.Format(fmtStr, "----", "--", "---", "---", "---", "---", "---", "-----", "-------"))
        End With
    End Sub
End Class

I've tried changing the structs to all string and trying to convert it to a double

Structure EmployeeInfo
        Dim FirstName() As String
        Dim LastName() As String
        Dim ID() As String
        Dim Mon() As String
        Dim Tue() As String
        Dim Wed() As String
        Dim Thu() As String
        Dim Fri() As String
    End Structure
...
...
...
...
...
   Data(i).Mon = line.Split(" "c)
   CDbl(Data(i).Mon
etc...

but it seems like no matter what I try, I keep getting the error 'Double cannot be derived from String'

Any hints or help?

This article has been dead for over six months. Start a new discussion instead.