Here is the original code.
I am suposeto be able to easily convert it to an array, but so far it has not been so easy!!
In this project I need to set up a row for the studentd and two columns for the grades
This is done as
and
Also I need a counter so I done
Then the rest of the dim statements are as before, here is the rest of my code
I have gotten some strnge results from this when I get it to out put some thing, it comes out something like string.input 0 0 1 0
But I assume that is because I have got the strings to read, store and divide up the infomation.
Then I need to get the columns to divide with each other because that will be were and what my grades are. When that is done that will give me my average. when I attempt to do this I get an error that tod 89 64 cast to double is invalid.
right know my error has to to with the input box. Something about trying to ad info that is less than my array or trying to divide by zero. not sure which one it was. Maybe aia have had both errors, anyway I will check back in the morning and hopefully I will get some advice that will lead me to a solution.
Code:
Private Sub btnGtGrades_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGtGrades.Click
Dim my As IO.StreamReader
Dim fmtStr As String = "{0,11}{1,4} {2,8} {3,6} {4,6}"
Dim strStudent, Start As String, strLetterGrade As String
Dim Grade1, Grade2, total As Double
Dim varEveryonesGrade As Double
Dim varAverage As Double
Dim sum As Double
varAverage = 0
sum = 0
If IO.File.Exists("A:\grades.txt") Then
my = IO.File.OpenText("A:\grades.txt")
Do While my.Peek <> -1
Start = my.ReadLine
strStudent = Start.Substring(0, 11)
Grade1 = Start.Substring(12, 4)
Grade2 = Start.Substring(16, 4)
varAverage = Math.Round((Grade1 + Grade2) / 2)
varEveryonesGrade += varAverage
sum += 1
Select Case varAverage
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
lstGtGrds.Items.Add(String.Format(fmtStr, strStudent, Grade1, Grade2, varAverage, strLetterGrade))
Loop
my.Close()
varEveryonesGrade = Math.Round(varEveryonesGrade / sum)
txtDsplyClsAvr.Text = "The class average is " & CStr(varEveryonesGrade)
Else
MsgBox("Try putting in the disk that has grades.txt on it!", , "Missing Disk")
End If
End Sub
I am suposeto be able to easily convert it to an array, but so far it has not been so easy!!
In this project I need to set up a row for the studentd and two columns for the grades
This is done as
Code:
Dim strStudent() As String
Code:
Dim grades( , ) As Double
Code:
Dim Counter As Integer
counter = 0
Code:
If IO.File.Exists("A:\grades.txt") Then
my = IO.File.OpenText("A:\grades.txt")
Do While my.Peek <> -1
Start = my.ReadLine
counter += 1
Loop
my.Close()
ReDim strStudent(counter)
my = IO.File.OpenText("A:\grades.txt")
strStudent(i) = my.ReadLine
ReDim Grades(counter, 2)
strStudent(row) = 1
Start = my.ReadLine
strStudent(strLetterGrade) = varAverage
For i = 2 To counter
If Grades(1, +2) \ 2 = varAverage Then
txtDsplyClsAvr.Text = "The class average is " & CStr(varEveryonesGrade)
End If
strStudent = Start.Substring(0, 11)
Grade1 = Start.Substring(12, 4)
Grade2 = Start.Substring(16, 4)
varAverage = Math.Round((Grade1 + Grade2) / 2, 0)
varEveryonesGrade += varAverage
sum += 1
Select Case varAverage
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
lstGtGrds.Items.Add(String.Format(fmtStr, strStudent, Grades, varAverage, strLetterGrade))
Next
my.Close()
varEveryonesGrade = Math.Round(varEveryonesGrade / sum)
Else
MsgBox("Try putting in the disk that has grades.txt on it!, , Missing Disk")
End If
But I assume that is because I have got the strings to read, store and divide up the infomation.
Then I need to get the columns to divide with each other because that will be were and what my grades are. When that is done that will give me my average. when I attempt to do this I get an error that tod 89 64 cast to double is invalid.
right know my error has to to with the input box. Something about trying to ad info that is less than my array or trying to divide by zero. not sure which one it was. Maybe aia have had both errors, anyway I will check back in the morning and hopefully I will get some advice that will lead me to a solution.