Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Structure Record
- Dim position As Integer
- Dim name As String
- Dim marks As Integer
- End Structure
- Dim student As Record
- Dim database(1000) As Record
- Dim filename As String = "Nov17_TestData.csv"
- Sub Main()
- Do
- Console.Clear()
- Console.WriteLine("1 - Load Leaderboard")
- Console.WriteLine("2 - Print Leaderboard")
- Console.WriteLine("3 - Save Leaderboard")
- Console.WriteLine("4 - Exit")
- Console.WriteLine("What would you like to do?")
- Dim choice As Integer = Console.ReadLine()
- Select Case choice
- Case 1
- loadLeaderboard()
- Case 2
- printLeaderboard()
- Case 3
- saveLeaderboard()
- End Select
- Loop
- End Sub
- Sub loadLeaderboard()
- Dim fieldSeparator As String = ","
- Dim recordSeparator As String = ";"
- 'Read the contents of the file
- Dim contents As String = My.Computer.FileSystem.ReadAllText(filename)
- 'Split the contents into records
- Dim record() As String = contents.Split(recordSeparator)
- For i As Integer = 0 To record.Length - 1
- 'Only read in records that are not empty
- If record(i).Trim <> String.Empty Then
- 'Split the record into fields
- Dim field() As String = record(i).Split(fieldSeparator)
- 'Copy the fields into the book
- student.position = field(0)
- student.name = field(1)
- student.marks = field(2)
- 'Add the item to the table
- database(student.position) = student
- End If
- Next
- End Sub
- Sub printLeaderboard()
- Console.WriteLine("Please enter the student ID to search: ")
- Dim userID As Integer = Console.ReadLine()
- Console.WriteLine("Position: " + database(userID).position)
- Console.WriteLine("First name: " + database(userID).name)
- Console.WriteLine("Marks: " + database(userID).marks)
- Console.ReadLine()
- End Sub
- Sub saveLeaderboard()
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement