Sorting a Collection by a certain field

Tech-Archive recommends: Speed Up your PC by fixing your registry



I have a question about the best way to sort a collection in VB. My
actual use is complicated so I've simplified it with the following
fake example:

I have created a class called "Person" in VB in an MS Access program.
As part of my code, I create a collection (called 'myRoom') of several
'Person' instances. One of the Person's properties is "wealth".
Every "day" in the program I want to sort the group of people in
"myRoom" by "wealth" to find who the 5 richest people are to run a few
functions on those people.

I can think of a few ways to do this, which would be best?

1) Some how sort the collection by the 'wealth' property. As best as
I can tell, there is no built in 'sort collection' function, so this
may not be possible.

2) Create a virtual temporary table in the visual basic code (dao
probably?) have one field being the person's location in the
collection, the other field being their wealth. As I cycle through
each person, add them to that table, then at the end, sort the table
and return the top 5 records. Run the function on those 5 people

3) Same as above but with a permanent table: Have a permanent table
in access with the same fields as above, first delete any existing
records in this 'PersonSortTable', then cycle through each person and
add them to the list, then sort the table and create a query to kick
out the top 5. Run the function on those 5 people


I'm not sure which way would be best. Would creating a permanent
table, deleting and appending data create a large bloat problem in the
database? Does a table that exists only in the visual basic code make
there be less bloat? Is there another option I'm missing.

Thanks to all,

.



Relevant Pages

  • One more "strlen" - was: Note to Chuck Crayne
    ... optimize strlen to shave one cycle off it, and you distribute your library to 1000 users, and they each write a program that uses strlen 1000 times, and distribute it to 1000 end-users, and they each run it ... We would of course only do strlen once per string, so we have to imagine we've got a lot of strings being thrown at us. ... When I click on the little hieroglyph to "sort by thread" instead of "sort by date", it takes - by wall clock - approximately a minute and fifteen seconds to complete. ... A better approach would be to keep a running index table for every column the user can sort by and every index table should be updated every time Thunderbird recieves an email/post...this way, the click on the glyph merrly selects which index table to use when picking what message headings to show in the window -- no need to run no freak'n algo. ...
    (alt.lang.asm)
  • Re: Sorting a Collection by a certain field
    ... so there isn't a chance to manually compact it. ... If bloat is a concern, ... I can tell, there is no built in 'sort collection' function, so this ... As I cycle through ...
    (microsoft.public.access.modulesdaovba)
  • Re: Note to Chuck Crayne
    ... know machine/assembly language, so you know what code you want to produce, and... ... you can produce HLL code that's "as good as" what you'd produce by any other means. ... optimize strlen to shave one cycle off it, and you distribute your library to 1000 users, and they each write a program that uses strlen 1000 times, and distribute it to 1000 end-users, and they each run it ... When I click on the little hieroglyph to "sort by thread" instead of "sort by date", it takes - by wall clock - approximately a minute and fifteen seconds to complete. ...
    (alt.lang.asm)
  • Re: OT: Happenings
    ... what sort of follow-up care will be needed. ... architectural firm and many of the people there cycle to work. ... have the bikes hung up on the wall and it all works out wonderfully. ... I am going to see what sort of work I can continue to do there after ...
    (alt.support.stop-smoking)
  • Re: OT: Happenings
    ... what sort of follow-up care will be needed. ... architectural firm and many of the people there cycle to work. ... have the bikes hung up on the wall and it all works out wonderfully. ... I am going to see what sort of work I can continue to do there after ...
    (alt.support.stop-smoking)