Hi everyone, I have to make a program that reads a txt file after reading it, show it in a richtext box and in another tab make the average of the grades the input received sort it by the student id and then in the same rtb sort it by the average of their grades, and finally save it on a new text file.

The text file input is something like this

12 3 10.0 6.9 7.3
19 2 6.7 9.3
10 3 4.5 9.3 4.5

and the output should look like this

sorted by student ID
10 6.1 4.5 9.3 4.5
12 8.1 10.0 6.9 7.3
19 5.3 6.7 9.3

sorted by grade average
12 8.1 10.0 6.9 7.3
10 6.1 4.5 9.3 4.5
19 5.3 6.7 9.3

As you noticed in the input the first number is the student ID, the second number is the number of tests made by the student, and the other 3 numbers are grades, in the output the first number is the student ID, the second number is the average of the tests, and the other 3 numbers are grades, I don't have a problem opening and saving a text file and neither creating a tab with 2 RTB , my problem is how do I tokenize or read the input line by line, i guess that i need to use the split function but I don't know how to implement it into the program.

Hope you can help me guys btw im using vb net 2008.

Thanks in advance

This should get you started:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
		Dim txtString As String() = System.IO.File.ReadAllLines("C:\file.txt")
		Dim studentList As New System.Collections.Generic.Dictionary(Of Integer, Decimal())

		For Each line As String In txtString
			If (String.IsNullOrEmpty(line)) Then
				Continue For
			End If
			Dim data As String() = line.Split(" ")
			Dim studentId As Integer = Convert.ToInt32(data(0))
			Dim gradeList As New List(Of Decimal)
			For i1 As Integer = 1 To data.Length - 1
			studentList.Add(studentId, gradeList.ToArray())
		'At this point you have it all in memory :)
	End Sub

Thank you so much for your help, that really helped me, it was pretty easy to understand your code, now i can implement it into my program thanks a lot :D:D

You're welcome

Please mark this thread as solved if you have received an answer to your question and good luck!