From: Tony Toews on
On Mon, 28 Jun 2010 15:10:38 -0400, "Jim Mack" <no-uce-ube(a)mdxi.com>
wrote:

>However, as a general rule you shouldn't swap the UDT elements
>directly, but use a separate long-integer Index array.

<snip>

>It's faster, and as a bonus you can have several index arrays that
>'sort' the UDT array on different criteria, and never change the UDT
>array at all.

Ahh, excellent concept.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/
Granite Fleet Manager http://www.granitefleet.com/
From: Phil Hunt on
If you go to the array route, why not use a hidden listbox control and dump
your text into it and then set the Sorted property to true.
Then just read it back and map the index

"Jim Mack" <no-uce-ube(a)mdxi.com> wrote in message
news:xPCdnYmP94AzbrXRnZ2dnUVZ_gWdnZ2d(a)giganews.com...
> Thomas Lerner wrote:
>> Hello all!
>>
>> I have a question about VB6:
>>
>> I have an array of UDTs:
>>
>> Public Type udtSpecial
>> Text As String
>> MyClass As Class1
>> End Type
>>
>> Public m() As udtSpecial
>>
>> I would like to sort this array by "Text".
>> Is this possible and if yes, how?
>
> With (almost) any sort there are two basic operations: compare and
> swap. In your case you'd make comparisons based on the Text field --
> if m(1).Text > m(2).Text Then..., but swap the entire UDTs. Swapping
> UDTs requires a separate Temp variable dimmed as the same type as the
> array.
>
> However, as a general rule you shouldn't swap the UDT elements
> directly, but use a separate long-integer Index array.
>
> First create a long-integer array with the same bounds as your UDT
> array. Fill the array with its own index, so that Index(9) contains
> the value "9" etc.
>
> Then when comparing, if m(Index(1)).Text > m(Index(2)).Text Then...,
> and when you need to swap, just swap the elements of the Index array,
> not the UDT array.
>
> It's faster, and as a bonus you can have several index arrays that
> 'sort' the UDT array on different criteria, and never change the UDT
> array at all.
>
> --
> Jim Mack
> Twisted tees at http://www.cafepress.com/2050inc
> "We sew confusion"
>


From: Larry Serflaten on

"Thomas Lerner" <t.lernernospam(a)hotmail.com> wrote

> I have an array of UDTs:
>
> Public Type udtSpecial
> Text As String
> MyClass As Class1
> End Type
>
> Public m() As udtSpecial
>
> I would like to sort this array by "Text".
> Is this possible and if yes, how?


For the simple answer, you would sort it in the same way as if it were an array of Strings,
or any other type of data:

Public m() As String

Pick a suitable sort algorithm, and substitute in your UDT for the type of variables
you need.

Having said that, Jim Mack's indirect indexing is a versatile solution....

LFS