Results 1 to 8 of 8

Thread: Top 10 out of 100?

  1. #1

    Thread Starter
    Lively Member newace's Avatar
    Join Date
    Mar 2001
    Posts
    127

    Top 10 out of 100?

    this is the scenario, i have 100 numbers (random). how do i get the highest 10 numbers from this set of numbers that i have.

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Sort them, and then take the first 10.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Lively Member newace's Avatar
    Join Date
    Mar 2001
    Posts
    127
    you can sort them using SQL, assume these values are in an array

  4. #4
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    Originally posted by newace
    you can sort them using SQL, assume these values are in an array
    +

    Is that an answer to yor question ?

  5. #5

    Thread Starter
    Lively Member newace's Avatar
    Join Date
    Mar 2001
    Posts
    127
    i meant you "CANT", it was a typo

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    Load them INTO an array, and then sort them into a NEW ARRAY. Then you can take the LAST 10, as they will be the highest, assuming that you sorted them in ascending order. There is a Bubble Sort example in the codebank, although writing you own isn't too hard.

  7. #7
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Look into the "Quicksort" sorting algorithm.

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Or put a hidden Listbox on your form and set its Sorted property to True. Place the numbers in the listbox using Format(MyNumber, "0000000") (if your number can be bigger than 9999999 or it has decimals then use the appropriate format) so they will all have the same number of characters.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width