Newbie Question. Adding the top 4 scores from 6 entries

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

OK, I'm sure this should be really simple, but I can't find the function I
need to use so could you experts point me in the right direction.

My form has 6 text boxes to enter his scores into (decimal scores to 2 dp).

Hit the 'calculate' button, and the total of the top 4 scores is displayed
in the result box.

Problem is... How do I do this in VB?

In Excel, it's no problem. Excel has the 'Large' function, so this excel
command will take 6 results and churm out the total of the top 4:

=LARGE(A1:A6,1)+LARGE(A1:A6,2)+LARGE(A1:A6,3)+LARGE(A1:A6,4)

Anyone know the equivilant function?
 
Haven't tried it but you could add them to an arraylist and then do the sort
method. Then you can take the top 4 you want.

Hope it helps.
Chris
 
Jan. 10, 2005

I was just working on what Chris posted. :) Here's the code:

Dim d(5) As Double
d(0) = txt1.text ' 3.23
d(1) = txt2.text ' 3.32
d(2) = ... ' 5
d(3) = ... ' 8
d(4) = ... ' 2.58
d(5) = ... ' 87.32
d.Sort(d) ' This sorts them, including decimals, with d(0) being the
least
' d(0) would be 2.58, d(1) = 3.23, etc.

Then you could display them in a listbox with this:

dim i as integer = 0
for i = 0 to 3 ' Limit of 4 top scores
listbox1.items.add(d(i))
next

I didn't test this but it should work! :) Hope you have a great day!


Joseph MCAD
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top