
Originally Posted by
RobertLees
Hi
I have a dynamic array. Each row contains 7 numeric values. I want to sort this array by field7 within field6 within field5, etc up to field1.
My first thought is to redim the array to give an empty row at the end, and use it to shiffle out of sequence rows. Or I could just dump the out-of-sequence row data into other fields.
What do you think ?
Regards
Robert
I'm an old time COBOL programmer and we sometimes used a bubble sort. I Googled it and found a Visual Basic version. Here is the link which contains some forms to test the results.
http://zone.ni.com/devzone/conceptd....256E5C000030C6
Here is the code.
VB Code:
Public Sub BubbleSort(ByRef sortArray() As Integer)
Dim i As Integer
Dim j As Integer
Dim Temp As Integer
For i = LBound(sortArray) To UBound(sortArray)
For j = LBound(sortArray) To (UBound(sortArray) - i - 1)
If sortArray(j + 1) < sortArray(j) Then
Temp = sortArray(j) 'swap if the two items
sortArray(j) = sortArray(j + 1) 'are out of order
sortArray(j + 1) = Temp
End If
Next j
Next i
End Sub
If this doesn't fit the bill Google on "bubble sort" some more.