What is the best way to sort a collection without screwing up the references and making a mess of things?
Say I have a collection made up of objects of a custom type called myObject.
myObject has 2 properties, myName and mySize
I want to be able to sort the collection called objCol by the mySize property into descending/asscending (doesn't matter which)
I want to do a simple bubble sort (as the collection, is not very large, 30 or so objects) but am having problems with the objects and their references.
here is the frame work that i have
dim i as long ,j as long , upper as long 'indices
dim myTempi as myObject
dim myTempj as myObject
upper = objCol.count
for i = 1 to upper - 1
set myTempi = objCol.item(i)
for j = i to upper
set myTempj = objCol.item(j)
if myTempi.mySize < myTempj.mySize then
'with a traditional array, I would assign
'one of the values to a temp variable in the
'swapping procedure. Unfortunately this doesn't
'seem to work right. I am thinking about trying
'to add the variables to a temporary collection
'then set it to the working collection. But for
'the life of me I can't seem to grasp the details,
' Any ideas would be appreciated
endif
next j
next i
Troy Williams B.Eng.
fenris@hotmail.com
Say I have a collection made up of objects of a custom type called myObject.
myObject has 2 properties, myName and mySize
I want to be able to sort the collection called objCol by the mySize property into descending/asscending (doesn't matter which)
I want to do a simple bubble sort (as the collection, is not very large, 30 or so objects) but am having problems with the objects and their references.
here is the frame work that i have
dim i as long ,j as long , upper as long 'indices
dim myTempi as myObject
dim myTempj as myObject
upper = objCol.count
for i = 1 to upper - 1
set myTempi = objCol.item(i)
for j = i to upper
set myTempj = objCol.item(j)
if myTempi.mySize < myTempj.mySize then
'with a traditional array, I would assign
'one of the values to a temp variable in the
'swapping procedure. Unfortunately this doesn't
'seem to work right. I am thinking about trying
'to add the variables to a temporary collection
'then set it to the working collection. But for
'the life of me I can't seem to grasp the details,
' Any ideas would be appreciated
endif
next j
next i
Troy Williams B.Eng.
fenris@hotmail.com