Hey all,
I'm new to VB.NET, and to programming altogether actually, and I need some help. I am making a program which stores the names and test scores of five students collected from input boxes into a two dimensional array; displays the data in a list box (student names in one column and their corresponding scores on the other); and displays the names and scores of the two highest scoring students in a second list box. The design is made up of two list boxes and three buttons. The first button prompts the user to enter the names and scores, the second displays the input, and the third displays the top two students and scores. I am using StreamWriter and StreamReader to transcribe the data stored in the array onto the list box with the second button, but I have absolutely no clue how to sort this data according to score. This is the code that I have written so far.
Public Class Form1
Dim fmtstr As String = "{0,-20} {1,4}"
Dim userInput(4, 1), strName_Score(4, 1) As String
Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
Dim i As Integer
Dim intNum As Integer = i + 1
'Enter data into input box and store into array
For i = 0 To 4
userInput(0, 0) = "Enter student 1's name."
userInput(0, 1) = "Enter student 1's score."
userInput(1, 0) = "Enter student 2's name."
userInput(1, 1) = "Enter student 2's score."
userInput(2, 0) = "Enter student 3's name."
userInput(2, 1) = "Enter student 3's score."
userInput(3, 0) = "Enter student 4's name."
userInput(3, 1) = "Enter student 4's score."
userInput(4, 0) = "Enter student 5's name."
userInput(4, 1) = "Enter student 5's score."
strName_Score(i, 0) = InputBox(userInput(i, 0), "Input Name")
strName_Score(i, 1) = InputBox(userInput(i, 1), "Input Score")
Next
'Store array as .txt file
Dim sw As IO.StreamWriter = IO.File.CreateText("StudentScores.txt")
For i = 0 To 4
sw.WriteLine(strName_Score(i, 0))
sw.WriteLine(strName_Score(i, 1))
Next
sw.Close()
End Sub
Private Sub btnInputData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInputData.Click
'Read .txt file and display input in list box
Dim sr As IO.StreamReader = IO.File.OpenText("StudentScores.txt")
dispInput.Items.Clear()
Do While sr.Peek <> -1
dispInput.Items.Add(String.Format(fmtstr, sr.ReadLine, sr.ReadLine))
Loop
End Sub
End Class
What do I do from here? Please explain, I want to learn as much as I can. Also, please let me know if there is anything I could have done or can still do to accomplish this task more efficiently. Thanks so much.