Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sorting 10 numbers and choosing the best 6

Posted on 2002-03-04
4
Medium Priority
?
182 Views
Last Modified: 2010-05-02
I have table that i created in MS aceess which has marks obtained by a student in 10 Exams, therefore I want a code that can choose the best 6 exams by the student and add their percentage and do the average of those 6 best exams.
0
Comment
Question by:Bush21
4 Comments
 
LVL 2

Accepted Solution

by:
damienm earned 220 total points
ID: 6838650
Private Sub Command1_Click()
Dim a(9) As Integer
Dim b(9) As Integer
Dim ival As Integer
Dim avgTopSix
a(0) = 55
a(1) = 67
a(2) = 29
a(3) = 33
a(4) = 54
a(5) = 62
a(6) = 22
a(7) = 33
a(8) = 43
a(9) = 25

For j = 0 To 9
    tmpInt = 0
    For i = 0 To 9
        If a(i) >= a(ival) Then
            ival = i
        End If
       
    Next i
    b(j) = a(ival)
    a(ival) = 0
Next j
For j = 0 To 9
    If j < 6 Then
        avgTopSix = avgTopSix + b(j)
    End If
    'MsgBox b(j)
Next j
MsgBox "The average of the top 6 scores is : " & avgTopSix / 6

End Sub
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6839383
This sounds like a homework assignment, so I'll only offer the logic, not the code:

1) Put the grades into an array
2) Sort the tests, highest grade to lowest
3) Pull off the first six array elements and get their sum
4) Display the sum divided by six
0
 
LVL 1

Expert Comment

by:mammouth
ID: 6839630
'this give you the top 6 best note from access table
"select top 6 note from table order by note desc"

add your 6 note and divide by 6

and its done
0
 

Author Comment

by:Bush21
ID: 6841210
Thanks man!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question