Sort Multidimensional arrays

06-27-08, 01:25 AM
|
|
New Member
|
|
Join Date: Jun 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Sort Multidimensional arrays
Does anyone have a function coded to sort a multidimensional array? I found one by Eric Repec-InetSolution but it didnt work. I dont want to recreate the wheel. thanks all!
|

06-28-08, 01:52 AM
|
 |
Community VIP
|
|
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
|
|
|
|

06-30-08, 08:04 PM
|
|
New Member
|
|
Join Date: Jun 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
|

07-01-08, 08:08 PM
|
|
New Member
|
|
Join Date: Jun 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Visual Basic 2D Array Sort
well it worked with a few tweaks. here's my updated version if anyone else needs it:
vb Code:
Public Sub SortArray(ByRef DArray(), Element As Integer) Dim gap As Integer, doneflag As Integer, SwapArray() Dim Index As Integer Dim acol As Integer Dim cnt As Integer ReDim SwapArray(2, UBound(DArray, 1), UBound(DArray, 2)) 'Gap is half the records gap = Int(UBound(DArray, 2) / 2) gap = gap + IIf(UBound(DArray, 2) Mod 2, 1, 0) Do While gap >= 1 Do doneflag = 1 'For Index = 0 To (UBound(DArray, 2) - (gap + 1)) For Index = 0 To (UBound(DArray, 2) - (gap)) 'Compare 1st 1/2 to 2nd 1/2 If DArray(Element, Index) > DArray(Element, (Index + gap)) Then For acol = 0 To (UBound(SwapArray, 2)) 'Swap Values if 1st > 2nd SwapArray(0, acol, Index) = DArray(acol, Index) SwapArray(1, acol, Index) = DArray(acol, Index + gap) Next For acol = 0 To (UBound(SwapArray, 2)) 'Swap Values if 1st > 2nd DArray(acol, Index) = SwapArray(1, acol, Index) DArray(acol, Index + gap) = SwapArray(0, acol, Index) Next cnt = cnt + 1 doneflag = 0 End If Next Loop Until doneflag = 1 gap = Int(gap / 2) Loop End Sub
Last edited by Nico; 07-02-08 at 02:27 AM.
Reason: Wrappers.
|

07-02-08, 08:01 AM
|
 |
Community VIP
|
|
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
|
|
Great. Thanks for posting your updated code.
Pete
|

10-17-08, 06:35 AM
|
|
New Member
|
|
Join Date: Oct 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
VB6 2 dimension Array sorting
Quote:
Originally Posted by digioz
Great. Thanks for posting your updated code.
Pete
|
Hi,
I having 2 dimension array. My data is looks like this
20.44002824, Sampletext
19.39352222, aaa
19.67565656, bbb
I want to sort the column 1, i need a output like this
20.44002824, Sampletext
19.67565656, bbb
19.39352222, aaa
Can you please help me. I dont know how to do this.
|

08-18-11, 08:09 AM
|
|
New Member
|
|
Join Date: Aug 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Great post digioz. My only change would be to change the Integer types to Long, as this is actually faster.
travimca,
run it as:
SortArray yourarray, 1
(assuming you index starts at 0)
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|