View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ernst Guckel[_4_] Ernst Guckel[_4_] is offline
external usenet poster
 
Posts: 34
Default sorting an array

Hello,

I use a sorting function (BubbleSort) to sort an array of data. The array
is 3 dimentions and it is being sorted by the first. I want it to sort by
the first then the second. Can anyone help me with this?

Here is the code now:

Function BubbleSort(TempArray As Variant)

Dim temp(71, 3) As Variant
Dim i As Integer
Dim NoExchanges As Integer

' Loop until no more "exchanges" are made.

Do

NoExchanges = True

' Loop through each element in the array.

For i = 1 To UBound(TempArray) - 1

' If the element is greater than the element
' following it, exchange the two elements.

If TempArray(i, 1) TempArray(i + 1, 1) Then
NoExchanges = False

temp(i, 1) = TempArray(i, 1)
temp(i, 2) = TempArray(i, 2)
temp(i, 3) = TempArray(i, 3)

TempArray(i, 1) = TempArray(i + 1, 1)
TempArray(i, 2) = TempArray(i + 1, 2)
TempArray(i, 3) = TempArray(i + 1, 3)

TempArray(i + 1, 1) = temp(i, 1)
TempArray(i + 1, 2) = temp(i, 2)
TempArray(i + 1, 3) = temp(i, 3)

End If

Next i

Loop While Not (NoExchanges)

End Function

Thanks,
Ernst.