PDA

View Full Version : Sorting a VB 2008 Array



jwil1
05-09-2008, 01:56 PM
Hi all,

How does one sort a VB 2008 Structure array...

I have created this Structure...


Public Structure Customer

Dim strName As String
Dim strItem As String
Dim decAmount As Decimal

End Structure


I have then declared an array of type Customer.

So now there is an array (of type Customer) which contains three of type Customer.

Code...


Customer(0).strName = "Mr A B"
Customer(0).strItem = "22-Inch LCD Monitor"
Customer(0).decAmount = 350

...


Customer(2).strName = "Mr C D"
Customer(2).stritem = "Asus Laptop"
Customer(2).decAmount = 1499


I would like to use the Array.Sort function if possible.

How can I sort them by decAmount??

dyewitness
05-09-2008, 02:25 PM
Have your structure implement IComparable (based on comparing decAmount).
http://msdn.microsoft.com/en-us/library/system.icomparable.aspx