Arrange points in increased order of X

Arrange points in increased order of X

Anonymous
Not applicable
297 Views
2 Replies
Message 1 of 3

Arrange points in increased order of X

Anonymous
Not applicable
I have a set of points in an array. I need to arrange those points in increased order of their X value(element 0), so that i can dimension them as dimContinue

InputArray = {{2,0,0},{1,0,0},{6,0,0}}
outputArray = {{1,0,0},{2,0,0},{6,0,0}}

Has any body got any idea how to it.

TIA
Irfan
0 Likes
298 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Irfan, Do a search for Sort methods if this doesn't help. "Quick Sort", "Bubble Sort" and others, depending on the size of your List, some are quicker than others. gl Paul 'Call to function. XP is a variant array of your values BubbleSortVariantArray XP 'Bubble Sort Function, one of many...Could add Option of 'Sorting High to Low / Low to High Public Sub BubbleSortVariantArray(avarIn() As Variant) ' Comments : Bubble-sorts the passed variant array ' Parameters: avarIn() array of variants ' Returns : Nothing Dim intLowBounds As Integer Dim intHighBounds As Integer Dim intX As Integer Dim intY As Integer Dim varTmp As Variant On Error GoTo PROC_ERR ' Get the bounds of the array intLowBounds = LBound(avarIn) intHighBounds = UBound(avarIn) ' For each element in the array For intX = intLowBounds To intHighBounds - 1 ' for each element in the array For intY = intX + 1 To intHighBounds ' If a value lower in the array is 'greater than a values higher in the ' array, swap them If avarIn(intX) > avarIn(intY) Then varTmp = avarIn(intX) avarIn(intX) = avarIn(intY) avarIn(intY) = varTmp End If Next intY Next intX PROC_EXIT: Exit Sub PROC_ERR: MsgBox "Error: " & Err.Number & ". " & Err.Description, , _ "BubbleSortVariantArray" Resume PROC_EXIT End Sub "irfan" wrote in message news:22809066.1107519267417.JavaMail.jive@jiveforum2.autodesk.com... >I have a set of points in an array. I need to arrange those points in >increased order of their X value(element 0), so that i can dimension them >as dimContinue > > InputArray = {{2,0,0},{1,0,0},{6,0,0}} > outputArray = {{1,0,0},{2,0,0},{6,0,0}} > > Has any body got any idea how to it. > > TIA > Irfan
0 Likes
Message 3 of 3

Anonymous
Not applicable
many thanks Paul,
0 Likes