Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. Module Module1
  2. Structure Record
  3. Dim position As Integer
  4. Dim name As String
  5. Dim marks As Integer
  6. End Structure
  7.  
  8. Dim student As Record
  9.  
  10. Dim database(1000) As Record
  11. Dim filename As String = "Nov17_TestData.csv"
  12. Sub Main()
  13. Do
  14. Console.Clear()
  15. Console.WriteLine("1 - Load Leaderboard")
  16. Console.WriteLine("2 - Print Leaderboard")
  17. Console.WriteLine("3 - Save Leaderboard")
  18. Console.WriteLine("4 - Exit")
  19. Console.WriteLine("What would you like to do?")
  20. Dim choice As Integer = Console.ReadLine()
  21. Select Case choice
  22. Case 1
  23. loadLeaderboard()
  24. Case 2
  25. printLeaderboard()
  26. Case 3
  27. saveLeaderboard()
  28. End Select
  29. Loop
  30.  
  31. End Sub
  32.  
  33. Sub loadLeaderboard()
  34. Dim fieldSeparator As String = ","
  35. Dim recordSeparator As String = ";"
  36.  
  37. 'Read the contents of the file
  38. Dim contents As String = My.Computer.FileSystem.ReadAllText(filename)
  39.  
  40. 'Split the contents into records
  41. Dim record() As String = contents.Split(recordSeparator)
  42.  
  43. For i As Integer = 0 To record.Length - 1
  44.  
  45. 'Only read in records that are not empty
  46. If record(i).Trim <> String.Empty Then
  47. 'Split the record into fields
  48. Dim field() As String = record(i).Split(fieldSeparator)
  49.  
  50. 'Copy the fields into the book
  51. student.position = field(0)
  52. student.name = field(1)
  53. student.marks = field(2)
  54.  
  55. 'Add the item to the table
  56. database(student.position) = student
  57. End If
  58. Next
  59. End Sub
  60.  
  61. Sub printLeaderboard()
  62. Console.WriteLine("Please enter the student ID to search: ")
  63. Dim userID As Integer = Console.ReadLine()
  64. Console.WriteLine("Position: " + database(userID).position)
  65. Console.WriteLine("First name: " + database(userID).name)
  66. Console.WriteLine("Marks: " + database(userID).marks)
  67. Console.ReadLine()
  68. End Sub
  69.  
  70. Sub saveLeaderboard()
  71.  
  72.  
  73. End Sub
  74. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement