Help with Streamreader

clowd71

New member
Joined
Nov 29, 2009
Messages
1
Programming Experience
Beginner
I need to get data from one text file and use it for a calculation in another text file. The first file has the students' current grade and the second file has the students' overall GPA,.
I need to get that current grade(named 'qp') out of the first streamreader so I can use it for my calculation but it only gives me the 'qp' of the last student in the first streamreader. Any ideas?? thanks

Here's the code:

Code:
Public srStudentfiles As New System.IO.StreamReader("c:\studentgradesnew.txt")
Sub Main()

Dim ID As String
Dim qp As Decimal
Dim names As String
Dim x As Decimal
Dim y As Decimal
Dim course As String
Dim credits As Decimal
Dim lettergrade As String


Dim tmpString As String
Dim tmpEntry() As String
Dim srStudentfiles As New System.IO.StreamReader("c:\studentgradesnew.txt")
While Not (srStudentfiles.EndOfStream)
tmpString = srStudentfiles.ReadLine()
tmpEntry = tmpString.Split("|")

ID = tmpEntry(0)
names = tmpEntry(1)
course = tmpEntry(2)
credits = tmpEntry(3)
lettergrade = tmpEntry(4)



System.Console.Write(" " & ID)
System.Console.Write(" " & names)
System.Console.Write(" " & course)
System.Console.Write(" " & credits)


Select Case lettergrade
Case Is = ("A")
qp = 4.0
Case Is = ("A-")
qp = 3.67
Case Is = ("B+")
qp = 3.33
Case Is = ("B")
qp = 3.0
Case Is = ("B-")
qp = 2.67
Case Is = ("C+")
qp = 2.33
Case Is = ("C")
qp = 2.0
Case Is = ("C-")
qp = 1.67
Case Is = ("D")
qp = 1.0
Case Is = ("F")
qp = 0.0
Case Is = ("UW")
qp = 0.0
End Select



System.Console.Write(" " & lettergrade)
System.Console.WriteLine(" " & qp.ToString("f2"))


End While

srStudentfiles.Close()


REM Now to combine the course grade with the students' record...

Dim newstudent As String
Dim newcredits As Decimal
Dim newqp As Decimal
Dim newyear As String

Dim newtmpString As String
Dim newtmpEntry() As String

Dim srStudentfilesNEW As New System.IO.StreamReader("c:\studentdirectory.txt")
While Not (srStudentfilesNEW.EndOfStream)
newtmpString = srStudentfilesNEW.ReadLine()
newtmpEntry = newtmpString.Split("|")
newstudent = newtmpEntry(0)
newcredits = newtmpEntry(1)
newqp = newtmpEntry(2)
newyear = newtmpEntry(3)


newcredits = newtmpEntry(1) + credits


System.Console.Write(" " & newstudent)
System.Console.Write(" " & newcredits)
System.Console.Write(" " & newqp)
If newcredits >= 97 Then
System.Console.WriteLine(" Senior")
ElseIf newcredits >= 65 Then
System.Console.WriteLine(" Junior")
ElseIf newcredits >= 33 Then
System.Console.WriteLine(" Sophomore")
ElseIf newcredits <= 32 Then
System.Console.WriteLine(" Freshman")
End If

x = (credits / newcredits) * newqp
y = (credits / newcredits) * qp

newqp = y + x
System.Console.WriteLine(newqp)






End While

srStudentfilesNEW.Close()


System.Console.ReadLine()
End Sub

these are the contents of the two text files:
studentdirectory.txt:
Coloe, B|5|3.00|Freshman
Johnson, j|64|2.56|Sophomore
Gordon, H|98|2.24|Senior
Roloson, D|43|3.30|Sophomore
Gaborik, M|87|4.00|Junior
Moore, D|41|3.75|Sophomore

studentgradesnew:
91|Coloe, B|cs101|3|B-
44|Johnson, j|cs101|3|B
56|Gordon, H|cs101|3|A
81|Roloson, D|cs101|3|B+
39|Gaborik, M|cs101|3|D
58|Moore, D|cs101|3|A-
 
Why not use a class to define the fields and then you can store them in a List(Of T) where you can add/remove/sort/parse them?
VB.NET:
Public Class Student
   Public client As String
   Public credits As Integer
   Public gp As Single
   Public year As String
End Class

Dim myStudents As New List(Of Student)
 
Back
Top