Displaying 20 Names and Marks in An Array

Today we were given the task of adapting Fridays program to display 20 names and scores from a listbox as well as working out the average mark as a percentage, in another one of Mr Strattons trademark programming tasks. As usual we were let loose on the computers, where, after 15 minutes of confusion and entering paragraphs of code, Mr Stratton questioned us as to who had actually jotted down a design before implementing it. He eventually posted a possible solution which is shown below:

Private Sub CmdStart_Click()
‘load an Array with data from a list box
‘list box is hidden on the form
‘List Boxes count from 0 so add a heading to the fist item
Dim IntNumber(20) As Integer
Dim StrName(20) As String
Dim intavg As Integer
Call Load_Array(IntNumber(), StrName())
Call Calc_Average(IntNumber(), intavg)
Call Display_Array(IntNumber(), StrName(), intavg)
End Sub

Private Sub Load_Array(ByRef Number() As Integer, ByRef StrName() As String)
Dim Counter As Integer ‘local Variable
For Counter = 1 To 20
Number(Counter) = LstNumbers.List(Counter)
StrName(Counter) = LstNames.List(Counter)
Next
End Sub

Private Sub Calc_Average(ByRef IntNumber() As Integer, ByRef intavg As Integer)
Dim IntSum As Integer
For Counter = 1 To 20
IntSum = IntSum + IntNumber(Counter)
Next
intavg = IntSum / 20
End Sub

Private Sub Display_Array(ByRef Number() As Integer, ByRef StrName() As String, ByVal intavg)
‘Standard procedure as used in previous programs
Dim Counter As Integer ‘local Variable
For Counter = 1 To 20
Form1.Print StrName(Counter) & ” scored ” & Number(Counter) & “%”
Next
Form1.Print “Average = ” & intavg & “%”
End Sub

And thats it folks, I’ll leave Danielle to fill you in with the rest.

2 thoughts on “Displaying 20 Names and Marks in An Array”

  1. Please put a link in referring to previous posts rather than copying and pasting. Blogs are subject to copyright in the same way that news papers are.

Comments are closed.