2 Replies - 234 Views - Last Post: 17 November 2012 - 10:05 AM Rate Topic: -----

#1 rjcast  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-November 12

Help with Structure and Data

Posted 17 November 2012 - 09:21 AM

Hi im new to the forum and was having trouble with some code. I am having trouble putting my data into my structured array and looping it to read each line of data for each part of my structure. Any Help at all would be greatly appreciated.
Thanks

*for the .letter part of my structure that is just there as a place holder to check to make sure it lined up with everything that will eventually be a function that will tell each students letter grade*

Data File: This is just part of the File there are 30 entries all together.
T.R. Alski 24 25 25 23 95.5
V.A. Borstellis 25 25 25 25 100.0
A.S. Reid 20 21 20 18 75.0
C.U. Tyler 19 20 21 24 75.5
H.A. Renee 20 23 23 25 80.5
I.A. Douglas 24 23 25 25 95.0
M.A. Elenaips 23 24 23 21 94.5
A.L. Emmet 21 19 18 15 73.0
S.U. James 21 24 23 22 87.5

 Imports System.IO

Public Class frmMain

    Structure student
        Dim firstName As String
        Dim lastName As String
        Dim quiz1 As Integer
        Dim quiz2 As Integer
        Dim quiz3 As Integer
        Dim quiz4 As Integer
        Dim project As Double
        Dim grade As Double
        Dim letter As Char
    End Structure

    Const MAXSTUDENTS As Integer = 29

    Private Sub btnReport_Click(sender As System.Object, e As System.EventArgs) Handles btnReport.Click

        Dim allStudents(MAXSTUDENTS) As student
        Dim reader As New StreamReader("studentData.txt")
        Dim txtFile() As String = File.ReadAllLines("studentData.txt")

        Dim fmtTitle As String = "{0,45}"
        Dim fmtSubTitle As String = "{0,42}"
        Dim fmtHead As String = "{0, -10} {1,-10} {2, -10} {3,-10} {4,-10} {5, -10} {6,-10} {7,-10} {8,-10}"

        Dim counter As Integer = 0

        lstReport.Items.Clear()
        lstReport.Items.Add(String.Format(fmtTitle, "Ole Country School"))
        lstReport.Items.Add(String.Format(fmtSubTitle, "Grade System"))
        lstReport.Items.Add("")
        lstReport.Items.Add(String.Format(fmtHead, "Name", "GPA", "Quiz 1", "Quiz 2", "Quiz 3", "Quiz 4", "Project", "Grade", "Letter"))
        lstReport.Items.Add(String.Format(fmtHead, "-----", "---", "------", "------", "------", "-------", "-------", "-----", "------"))

        txtFile = reader.ReadLine.Split(" "c)


        With allStudents(counter)
            .firstName = txtFile(0)
            .lastName = txtFile(1)
            .quiz1 = CInt(txtFile(2))
            .quiz2 = CInt(txtFile(3))
            .quiz3 = CInt(txtFile(4))
            .quiz4 = CInt(txtFile(5))
            .project = CDbl(txtFile(6))
            .letter = CChar("A")
        End With
        counter += 1

        For i As Integer = 0 To allStudents.GetUpperBound(0)

            lstReport.Items.Add(String.Format(fmtHead, allStudents(i).firstName, allStudents(i).lastName, allStudents(i).quiz1,
                                              allStudents(i).quiz2, allStudents(i).quiz3, allStudents(i).quiz4,
                                              allStudents(i).project, "", allStudents(i).letter))
        Next

    End Sub
End Class




Is This A Good Question/Topic? 0
  • +

Replies To: Help with Structure and Data

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,361
  • Joined: 02-June 10

Re: Help with Structure and Data

Posted 17 November 2012 - 09:51 AM

I don't know anyone that actually use structures like this anymore. Not for the last 10+ years. I use them now and again when I have to talk down to an API that is built for multiple languages and multiple OSes, thus has to use the lowest common denominator.

But for VB.NET we use classes for this type of need. There's a link to a tutorial on classes in my signature block. Its in C# but they are both .NET languages so you should be able to read enough to let you compose in your own VB.NET. Most important is the concepts within the tutorial.

Next: "I'm having trouble" doesn't really tell us anything. Is your app crashing, throwing exception errors, just producing results different than you expected??
Was This Post Helpful? 0
  • +
  • -

#3 rjcast  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-November 12

Re: Help with Structure and Data

Posted 17 November 2012 - 10:05 AM

No the trouble is that i can make the first line in the data file show up into my list box but i cant get the rest of the of the data to the list. And thank you for the link i will take a look into classes.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1