![]() | |
#11
| |||
| |||
|
|
Scott wrote: I have a collection where the items in the collection are dates. I want to iterate over the collection and build a value list string for the rowsource of a listbox. The dates in the collection are not in chronological order. Is there a way to first sort the collection and put the dates in chronological order before creating the value list string? Or, how would I iterate over the collection pulling out the dates in chronological order? I just had a thought. The Add method has an optional Before argument that you could use to add new items in a sorted order. Maybe you can adapt this to your needs: Private colMySorted As New Collection Public Sub AddSorted(lngValue) Dim K As Long If colMySorted.Count > 0 Then For K = 1 To colMySorted.Count If lngValue < colMySorted(K) Then colMySorted.Add lngValue, , K Exit Sub End If Next K End If colMySorted.Add lngValue End Sub -- Marsh MVP [MS Access] |
#12
| |||
| |||
|
|
Scott wrote: I have a collection where the items in the collection are dates. I want to iterate over the collection and build a value list string for the rowsource of a listbox. The dates in the collection are not in chronological order. Is there a way to first sort the collection and put the dates in chronological order before creating the value list string? Or, how would I iterate over the collection pulling out the dates in chronological order? I just had a thought. The Add method has an optional Before argument that you could use to add new items in a sorted order. Maybe you can adapt this to your needs: Private colMySorted As New Collection Public Sub AddSorted(lngValue) Dim K As Long If colMySorted.Count > 0 Then For K = 1 To colMySorted.Count If lngValue < colMySorted(K) Then colMySorted.Add lngValue, , K Exit Sub End If Next K End If colMySorted.Add lngValue End Sub -- Marsh MVP [MS Access] |
#13
| |||
| |||
|
|
This will work great by sorting as items are added. BTW, there should be only one comma before K since we are using the Before parameter. Scott wrote: I have a collection where the items in the collection are dates. I want to iterate over the collection and build a value list string for the rowsource of a listbox. The dates in the collection are not in chronological order. Is there a way to first sort the collection and put the dates in chronological order before creating the value list string? Or, how would I iterate over the collection pulling out the dates in chronological order? "Marshall Barton" wrote I just had a thought. The Add method has an optional Before argument that you could use to add new items in a sorted order. Maybe you can adapt this to your needs: Private colMySorted As New Collection Public Sub AddSorted(lngValue) Dim K As Long If colMySorted.Count > 0 Then For K = 1 To colMySorted.Count If lngValue < colMySorted(K) Then colMySorted.Add lngValue, , K Exit Sub End If Next K End If colMySorted.Add lngValue End Sub |
#14
| |||
| |||
|
|
The application is for training courses and has a calendar that displays the schedule of existing courses. I am working on a way to add new courses to the schedule. A course may have multiple dates. The first step is that the user clicks on any date on the calendar and that date is added to the collection. The application can not rely on the user entering dates in chronological order. Also a date may be deleted and another date put in its place. |
|
So I need a way to sort the dates once they are all in the collection. The bubblesort should work using MyCollection.Item(i). I prefer not to use the second collection just to avoid the extra overhead. |
|
Once the dates are in the collection on the proper order, the app will open a data entry screen for entering the new course. The data entry form will have a listbox that displays the dates in the collection and after the course title and other data is entered, the user will click a button to add the dates to a course subform. |
#15
| |||
| |||
|
|
As you've probably already figured out, the Before argument is the THIRD argument of the Add method. The second argument is the key argument, so you really do need two commas (unless you are using a named argument). If you are using the Key argument (my example didn't), of course there would only be one comma between the Key and Before arguments (the first comma is between the Item and Key arguments). -- Marsh MVP [MS Access] Scott wrote: This will work great by sorting as items are added. BTW, there should be only one comma before K since we are using the Before parameter. Scott wrote: I have a collection where the items in the collection are dates. I want to iterate over the collection and build a value list string for the rowsource of a listbox. The dates in the collection are not in chronological order. Is there a way to first sort the collection and put the dates in chronological order before creating the value list string? Or, how would I iterate over the collection pulling out the dates in chronological order? "Marshall Barton" wrote I just had a thought. The Add method has an optional Before argument that you could use to add new items in a sorted order. Maybe you can adapt this to your needs: Private colMySorted As New Collection Public Sub AddSorted(lngValue) Dim K As Long If colMySorted.Count > 0 Then For K = 1 To colMySorted.Count If lngValue < colMySorted(K) Then colMySorted.Add lngValue, , K Exit Sub End If Next K End If colMySorted.Add lngValue End Sub |
#16
| |||
| |||
|
|
Scott wrote: The application is for training courses and has a calendar that displays the schedule of existing courses. I am working on a way to add new courses to the schedule. A course may have multiple dates. The first step is that the user clicks on any date on the calendar and that date is added to the collection. The application can not rely on the user entering dates in chronological order. Also a date may be deleted and another date put in its place. I think I can understand that :-). I am a little surprised to see you use a Collection for this. A (temporary) table would do perfectly, and then you don't have to worry about sorting, the database will do that for you. So I need a way to sort the dates once they are all in the collection. The bubblesort should work using MyCollection.Item(i). I prefer not to use the second collection just to avoid the extra overhead. I am afraid the overhead in bubblesort is significantly larger, as you have to swap items all the time. Once the dates are in the collection on the proper order, the app will open a data entry screen for entering the new course. The data entry form will have a listbox that displays the dates in the collection and after the course title and other data is entered, the user will click a button to add the dates to a course subform. The listbox can be based on the temp table. It makes the job easier, I think, and less reliant on code hence less sensitive to maintenance. -- Bas Cost Budde, Holland http://www.heuveltop.nl/BasCB/msac_index.html I prefer human mail above automated so in my address replace the queue with a tea |
#17
| |||
| |||
|
|
I decided to use a collection rather than a temp table out of concern that a temp table would cause bloat of the database file. Numerous courses are scheduled each month so there would be a lot of adding records and deleting records to and from the temp table. |
#18
| |||
| |||
|
|
The application is for training courses and has a calendar that displays the schedule of existing courses. I am working on a way to add new courses to the schedule. A course may have multiple dates. The first step is that the user clicks on any date on the calendar and that date is added to the collection. The application can not rely on the user entering dates in chronological order. Also a date may be deleted and another date put in its place. So I need a way to sort the dates once they are all in the collection. The bubblesort should work using MyCollection.Item(i). I prefer not to use the second collection just to avoid the extra overhead. Once the dates are in the collection on the proper order, the app will open a data entry screen for entering the new course. The data entry form will have a listbox that displays the dates in the collection and after the course title and other data is entered, the user will click a button to add the dates to a course subform. Scott "Bas Cost Budde" <b.costbudde (AT) heuvelqop (DOT) nl> wrote in message news:cpt36v$olk$1 (AT) news2 (DOT) solcon.nl... Scott wrote: The collection will have ten items at most. How can I apply the bubblesort routine to rearranging the dates in the collection to chronological order? One other question first: how do the dates get into this collection? If you can do any form of insertion sort, that would save a lot of effort. I can make a sorting function for a collection "tomorrow" (whatever that means on this earth, taking time zones into consideration--mine is GMT+1) but maybe you can play a bit: Create a new collection * loop the old collection, comparing every element to the new collection * insert the element in the right place Return the new collection (don't forget to clean up the old one!) -- Bas Cost Budde, Holland http://www.heuveltop.nl/BasCB/msac_index.html I prefer human mail above automated so in my address replace the queue with a tea |
#19
| |||
| |||
|
|
I decided to use a collection rather than a temp table out of concern that a temp table would cause bloat of the database file. |
![]() |
| Thread Tools | |
| Display Modes | |
| |