Here is the text file I must use and it must be wrote in this manner.
Grades.txt
Todd 33 94
Bill 82 69
Betty 89.5 89.5
I must use it this way, I can not rewrite it to were the data is on separate lines. Wish I could it would be easier to work with.
I am useing a label, A List Box A button.
This project creates a grade calculator.
I almost have it figured out but I still am having a snag.
Here is my code
The problem is with ripping the bits of info from the file.
Now my error is telling my that on the line
Grade2 = Var2.Substring(2, 5) that the info must be obtained within valid parameters? Then if whem that is fixed my next error with probable be my mathematical because my grades are no longer dimensioned as double.
I actually this I need to be able to rip the info from the data file have the lines Grade2 = Var2.Substring(2, 5) in a different manner. Because when I do my math (Grade1 + Grade2) / 2 ...
All the info should be dimed as double. Oh Yea then I have to display the class average in a textBox. I dont think thats gonna be a problem once I get past this.
Grades.txt
Todd 33 94
Bill 82 69
Betty 89.5 89.5
I must use it this way, I can not rewrite it to were the data is on separate lines. Wish I could it would be easier to work with.
I am useing a label, A List Box A button.
This project creates a grade calculator.
I almost have it figured out but I still am having a snag.
Here is my code
Code:
Dim my As IO.StreamReader = IO.File.OpenText("a:\grades.txt")
Private Sub btnGtGrades_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGtGrades.Click
Dim fmtStr As String = "{0,-12}{1,-5}{2,-5}{3,-5}{4,-2}"
Dim strStudent As String, strLetterGrade As String
Dim Grade1, Grade2 As String
Dim varEveryonesGrade As Double
Dim varAverage As Double
Dim Var1, Var2 As String
strStudent = strStudent
Var1 = "Grade1"
Var2 = "Grade2"
strStudent = my.ReadLine
strStudent = strStudent.Substring(0, 12)
Grade1 = Var1.Substring(1, 5)
Grade2 = Var2.Substring(2, 5)
varAverage = (Var1 + Var2) / 2
If varAverage >= 90 Then
strLetterGrade = "A"
End If
If varAverage >= 80 Then
strLetterGrade = "B"
End If
If varAverage >= 70 Then
strLetterGrade = "C"
End If
If varAverage >= 60 Then
strLetterGrade = "D"
End If
If varAverage >= 50 Then
strLetterGrade = "F"
End If
lstGtGrds.Items.Add(String.Format(fmtStr, Grade1, Grade2, varAverage, strLetterGrade))
Now my error is telling my that on the line
Grade2 = Var2.Substring(2, 5) that the info must be obtained within valid parameters? Then if whem that is fixed my next error with probable be my mathematical because my grades are no longer dimensioned as double.
I actually this I need to be able to rip the info from the data file have the lines Grade2 = Var2.Substring(2, 5) in a different manner. Because when I do my math (Grade1 + Grade2) / 2 ...
All the info should be dimed as double. Oh Yea then I have to display the class average in a textBox. I dont think thats gonna be a problem once I get past this.