|
-
Nov 1st, 2005, 06:37 AM
#1
Thread Starter
Hyperactive Member
sorting an array
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
-
Nov 1st, 2005, 06:50 AM
#2
New Member
Re: sorting an array
Give it a try and see if it works.
If it does i think you are correct.
If not i think you are wrong
-
Nov 1st, 2005, 07:12 AM
#3
Re: sorting an array
 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.
-
Nov 1st, 2005, 07:20 AM
#4
Re: sorting an array
You could google for sorting methods and VB source code to find a lot of improved sorting methods as well
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|