Need Help bad & fast

Jblake00

Well-known member
Joined
Sep 27, 2003
Messages
76
I got a huge data file with info from microfoft.
I have a project that I have been working on for days I am not quite getting something down. I am trying to do an array that get names() and grades( , ) from a text file. Then it should count the number of students and get the 2 grades and then create an average grade and then a letter grade. Also it will display a class average in a text box. the rest of the info will be displayed in a text box. Some of it I have an idea of how to do but to be honest I am lost on doing a nested loop. I dont understand how this works also I for some reason want to or think I need sub functions.
I wish I had a VB.net buddy I could chat with on yahoo. I hate to admit it but I need a tutor. If anyone is interested my yahoo handle is mental_maynard just add somekind of message that contains the words VB.net.... Also I am willing to do a different messanger to get programing help if need be.
 
Well I can see I am getting no interest here. So lets try my code and see if someone can point out were I need to check it and for what. Btw this is probably the closest I have gottten to my goal.
Code:
 Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
        Dim my As IO.StreamReader
        Dim student() As String
        Dim grades(,) As Double
        Dim i, keepCount As Integer
        Dim start As String
        keepCount = 0
        If IO.File.Exists("a:\name.txt") Then
            my = IO.File.OpenText("A:\name.txt")
            Do While my.Peek <> -1
                start = my.ReadLine

                keepCount += 1

            Loop
            my.Close()

            my = IO.File.OpenText("a:\name.txt")
            Dim fmtStr As String = "{0,11}{1,4} {2,8}  {3,6}     {4,6}"
            Dim row, col As String
            Dim grade1, grade2, total As Double
            ReDim student(keepCount)
            ReDim grades(keepCount, 2)
            Dim average As Double
            Dim strLetterGrade As ImeMode
            grade1 = row
            grade2 = col

            For i = 1 To student(i) keepCount
                start = my.ReadLine
                student(i) = start.ToCharArray(0, 20)
                student(i).Substring(0, 11)
                lstBox.Items.Add(student(i))
            Next i
            For grade1 = 1 To grades(keepCount, 2)
                grade1.Parse(12, 4)
                If grades(keepCount, 2) > 0 Then
                    student(keepCount) = student(keepCount) + grades(keepCount, 2)

                    lstBox.Items.Add(grade1)
                End If
            Next grade1
            For grade2 = 2 To grades(keepCount, 2)
                grade2.Parse(16, 4)
                If grades(keepCount, 2) > 0 Then
                    student(keepCount) = student(keepCount) + grades(keepCount, 2)

                    lstBox.Items.Add(grade2)
                    average += (grade1 + grade2) / 2
                End If
            Next grade2
            For strLetterGrade = keepCount To student(i)

                Select Case average
                    Case Is >= 90
                        strLetterGrade = "A"
                    Case Is >= 80
                        strLetterGrade = "B"
                    Case Is >= 70
                        strLetterGrade = "C"
                    Case Is >= 60
                        strLetterGrade = "D"
                    Case Is >= 50
                        strLetterGrade = "F"
                End Select
            Next strLetterGrade
            lstBox.Items.Add(String.Format(fmtStr, student, grade1, grade2, average, strLetterGrade))


            my.Close()
            total = Math.Round(total / keepCount)

            txtDsplyClsAvr.Text = "The class average is " & CStr(total)

        Else

                MsgBox("Try putting in the disk that has grades.txt on it!", , "Missing Disk")




        End If
            average = (grade1 + grade2) / 2

            Next


    End Sub
    
End Class
ohh yea suppose I should say what I am getting out of it.
Here is what the input bos displays.
System.String[] 1 2 0 15
And the text box says the class average is 0.
Why am I not get all my names grades and averages?
And why in the devil did it say the letter grade is 15 instead of an F or something?
 
Hey JBlake.

I felt bad that no - one posted a reply. Here is my feeble attempt.

To be honest, that is a heck of amount of code to be wrapped in one class. I had some issues understanding how the file youre reading is structured, what youre passing to the arrays, what type of arrays youre using, etc. My suggestions....

Break into a couple of classes or at least a couple of functions with some class variables (like an arraylist). Heres a little help that might get you on the write track.

Private myarray as ArrayList()

Sub ReadDisk(ByVal disklocation as string)
dim sr as streamreader = new streamreader(disklocation)
dim textline as string

textline = sr.readline()
while Not textline=Nothing
\\Call function that adds these values to the arraylist
AddValues(textline)
end while

end sub

Sub AddVales(ByVal thegradesandsuch as String)
\\do something with the first value before the comma
\\after the comma
\\and again - for example
myarry.Add(the concatenated value you want from the String)
end sub

Function GetAverage()
Dim mynum as Double = 0.0
Dim counter as Object

For each counter in ArrayList
nynum += arraylist(counter)
next

return mynum

end function

You get the idea. I would look at using a String Collection object or some other more efficient arrat object as you didnt specify how many grades there would be for each student.

Well, I hope this helps a little - its not full code and more pseudo-code than anything else, but it gets you thinking more from an OOP standpoint.

inzo
 
Ok let my tell you a little bit. the text go like this
Tod 33 95
ditto
and ditto you get the point
First off I am demimension some items
Code:
   Dim my As IO.StreamReader
        Dim student() As String
        Dim grades(,) As Double
        Dim i, keepCount As Integer
        Dim start As String
        keepCount = 0
        If IO.File.Exists("a:\name.txt") Then
            my = IO.File.OpenText("A:\name.txt")
            Do While my.Peek <> -1
                start = my.ReadLine

                keepCount += 1

            Loop
            my.Close()
If I am useing the wrong type for streamReader please tell me.
The student() must be string As far as I know
I am possitive the grades( ,) must be double
Then I have to redim the student and grades.
Then the rest of it has to be a nested loop.
I will move my other dim statements to the top later after I get proper results. I wish I had of made myself do some practice nested loop programs before hand and a array so I would have a better understanding of things. One of my bigest problems is the text book does everything with files that are contructed like this
tod
33
95
But the instructer had to put a monkey wrench into it.
Besides that I cant figure out why we arent using a begging level book by microsoft, after all they wrote the program!!!
I guess if I cant accomplish this tonight I will have to stay home from work tomorrow. Program due tomorrow night, errrrr.
 
Last edited by a moderator:
Oh well I played hookey from work and tryed all night last night and the bigest part of today, unfornunatly it never fell together for me " :o :( :mad: :rolleyes: " This is the first time I done really lousy with a program... Oh Well at this point I just want the instructor to explain to me what I am doing wrong... Only five more classes after tonight. Sure hope I pass with a C at least....
 
Back
Top