Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. Private Sub cmdStart_Click()
  2.  
  3.  
  4. 'Initalise variables'
  5. Dim coursework(14) As Integer
  6. Dim exam(14) As Integer
  7. Dim percent(14) As Integer
  8. Dim total(14) As Integer
  9. Dim name(14) As String
  10. Dim target As String
  11.  
  12.  
  13. 'Calls data from
  14. Call read_file(name(), exam(), coursework(), total(), percent())
  15.  
  16. Call Display(percent(), name())
  17. Call count_occurrences(percent())
  18. Call FindMax(percent(), name())
  19. End Sub
  20.  
  21. Private Sub read_file(ByRef name() As String, ByRef exam() As Integer, ByRef coursework() As Integer, ByRef total() As Integer, ByRef percent() As Integer)
  22. Dim counter As Integer
  23.  
  24. Open "Unit Assessment.txt" For Input As #1
  25.  
  26. 'collects data from external text file'
  27. For counter = 0 To 14
  28.  
  29. Input #1, name(counter)
  30.  
  31. Input #1, exam(counter)
  32.  
  33. Input #1, coursework(counter)
  34.  
  35. Next
  36.  
  37. Close #1
  38.  
  39. 'calculate percentage for every person entered in the file'
  40. For counter = 0 To 14
  41.  
  42. total(counter) = exam(counter) + coursework(counter)
  43. percent(counter) = total(counter) / 150 * 100
  44.  
  45. Next
  46. End Sub
  47.  
  48.  
  49. Private Sub Display(ByRef percent() As Integer, ByRef name() As String)
  50. 'displays the percentage and grade of the students
  51. Dim counter As Integer
  52. For counter = 0 To 14
  53. 'Displays pupils grade'
  54. 'If the percent is equal to or a above the amount untill the next fresh hold then displays the name, percent and grade they achived'
  55. Select Case percent(counter)
  56. Case Is >= 70: picDisplay.Print (name(counter) & " has recieved " & percent(counter) & " % You have achevied an A")
  57. Case Is >= 60: picDisplay.Print (name(counter) & " has recieved " & percent(counter) & " % You have achevied a B")
  58. Case Is >= 50: picDisplay.Print (name(counter) & " has recieved " & percent(counter) & " % You have achevied a C")
  59. Case Is >= 45: picDisplay.Print (name(counter) & " has recieved " & percent(counter) & " % You have achevied a D")
  60. Case Is < 45: picDisplay.Print (name(counter) & " has recieved " & percent(counter) & " % No Grade")
  61.  
  62. End Select
  63. Next
  64.  
  65. End Sub
  66.  
  67. Private Sub count_occurrences(ByRef percent() As Integer)
  68. 'counting occurrences on array of strings
  69.  
  70. Dim pointer As Integer
  71. Dim counter As Integer
  72.  
  73. counter = 0
  74. For pointer = 0 To 14
  75. 'If the percentage is greater than or equal to 70 then 1 is added to counter'
  76. If percent(pointer) >= 70 Then
  77. 'adds 1 to counter when someone scores an a'
  78. counter = counter + 1
  79. End If
  80.  
  81. Next
  82. 'Displays howmany people achieved an a'
  83. picDisplay.Print ("A's" & " occurred " & counter & " times in that list")
  84. End Sub
  85.  
  86. Private Sub FindMax(ByRef percent() As Integer, ByRef name() As String)
  87. 'Initalise variables'
  88. Dim counter As Integer
  89. Dim max As Integer
  90. Dim Pupil As String
  91.  
  92.  
  93. For counter = 0 To 14
  94. 'Takes the highest variable in the array and sets it to the max'
  95. If max < percent(counter) Then
  96. Pupil = name(counter)
  97. max = percent(counter)
  98. End If
  99. Next
  100. 'Displays the highest mark and who it was scored by'
  101. picDisplay.Print "The highest mark was " & max & "% " & " scored by " & Pupil
  102.  
  103.  
  104.  
  105. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement