Here is a rought translation to .NET although you could use the Compatiblity namespace to use almost the same code you have there.
VB Code:
Dim filepath As String = "C:\Code\Practice\TestBed9\bin\grades.txt" 'create arrays (or in this case arraylists) Dim labs As New ArrayList Dim questions As New ArrayList Dim tests As New ArrayList Dim participations As New ArrayList 'open file Dim fs As New IO.FileStream(filepath, FileMode.Open) 'create reader for file Dim sr As New IO.StreamReader(fs) 'read until there is no more to read Do While sr.Peek > -1 'read one line at a time Dim line As String = sr.ReadLine 'parse into fields Dim fields() As String = line.Split(Char.Parse(",")) 'test for student match If fields(0) = cboStudent.Text Then 'name Select Case fields(1) 'type Case "Lab" labs.Add(fields(2)) 'grade Case "Questions" questions.Add(fields(2)) 'grade Case "Tests" tests.Add(fields(2)) 'grade Case "Participation" participations.Add(fields(2)) 'grade End Select End If Loop 'close and release file fs.Close()
Also there could be a number of improvements if you wanted to go OOP with it. You could then make a Grades or Student class/collection and just serialize/deserialize it to and from disc. Then there is no parsing required and you can keep the data in memory for faster access.




Reply With Quote