M
mpfohl
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,
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,