Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub cmdStart_Click()
- 'Initalise variables'
- Dim coursework(14) As Integer
- Dim exam(14) As Integer
- Dim percent(14) As Integer
- Dim total(14) As Integer
- Dim name(14) As String
- Dim target As String
- 'Calls data from
- Call read_file(name(), exam(), coursework(), total(), percent())
- Call Display(percent(), name())
- Call count_occurrences(percent())
- Call FindMax(percent(), name())
- End Sub
- Private Sub read_file(ByRef name() As String, ByRef exam() As Integer, ByRef coursework() As Integer, ByRef total() As Integer, ByRef percent() As Integer)
- Dim counter As Integer
- Open "Unit Assessment.txt" For Input As #1
- 'collects data from external text file'
- For counter = 0 To 14
- Input #1, name(counter)
- Input #1, exam(counter)
- Input #1, coursework(counter)
- Next
- Close #1
- 'calculate percentage for every person entered in the file'
- For counter = 0 To 14
- total(counter) = exam(counter) + coursework(counter)
- percent(counter) = total(counter) / 150 * 100
- Next
- End Sub
- Private Sub Display(ByRef percent() As Integer, ByRef name() As String)
- 'displays the percentage and grade of the students
- Dim counter As Integer
- For counter = 0 To 14
- 'Displays pupils grade'
- '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'
- Select Case percent(counter)
- Case Is >= 70: picDisplay.Print (name(counter) & " has recieved " & percent(counter) & " % You have achevied an A")
- Case Is >= 60: picDisplay.Print (name(counter) & " has recieved " & percent(counter) & " % You have achevied a B")
- Case Is >= 50: picDisplay.Print (name(counter) & " has recieved " & percent(counter) & " % You have achevied a C")
- Case Is >= 45: picDisplay.Print (name(counter) & " has recieved " & percent(counter) & " % You have achevied a D")
- Case Is < 45: picDisplay.Print (name(counter) & " has recieved " & percent(counter) & " % No Grade")
- End Select
- Next
- End Sub
- Private Sub count_occurrences(ByRef percent() As Integer)
- 'counting occurrences on array of strings
- Dim pointer As Integer
- Dim counter As Integer
- counter = 0
- For pointer = 0 To 14
- 'If the percentage is greater than or equal to 70 then 1 is added to counter'
- If percent(pointer) >= 70 Then
- 'adds 1 to counter when someone scores an a'
- counter = counter + 1
- End If
- Next
- 'Displays howmany people achieved an a'
- picDisplay.Print ("A's" & " occurred " & counter & " times in that list")
- End Sub
- Private Sub FindMax(ByRef percent() As Integer, ByRef name() As String)
- 'Initalise variables'
- Dim counter As Integer
- Dim max As Integer
- Dim Pupil As String
- For counter = 0 To 14
- 'Takes the highest variable in the array and sets it to the max'
- If max < percent(counter) Then
- Pupil = name(counter)
- max = percent(counter)
- End If
- Next
- 'Displays the highest mark and who it was scored by'
- picDisplay.Print "The highest mark was " & max & "% " & " scored by " & Pupil
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement