Hello,
I'm trying to get my 2D-array sorted but for some reason I can't seem to get it sorted in the right order. Anybody that can help me find the solution?
I have an array which has been constructed as follows
I'm using the last two columns as a way to define the order.
The value that needs to be sorted is the 4th column (Total).
But instead of actually changing the indexes, I want to change the value of the column New Position.
So to give you an example:
BEFORE SORT
AFTER SORT
As you can see, only the value in the last column has changed depending on the value of the 4th column.
I'm using this last column to define the order in which I'm displaying this array. But I need to be able to keep track of the original position (the second to last column).
Right now I'm using the following code:
Thanks for the help!
I'm trying to get my 2D-array sorted but for some reason I can't seem to get it sorted in the right order. Anybody that can help me find the solution?
I have an array which has been constructed as follows
Code:
array (Name, Number1, Number2, Total, Previous Position, New Position)
The value that needs to be sorted is the 4th column (Total).
But instead of actually changing the indexes, I want to change the value of the column New Position.
So to give you an example:
BEFORE SORT
Code:
person(0) ("NAME1", 4, 51, 55,1,1)
person(1) ("NAME2", 12, 41, 53,2,2)
person(2) ("NAME3", 24, 35, 59,3,3)
person(3) ("NAME4", 1, 11, 12,4,4)
person(4) ("NAME5", 0, 22, 22,5,5)
Code:
person(0) ("NAME1", 4, 51, 55,1,2)
person(1) ("NAME2", 12, 41, 53,2,3)
person(2) ("NAME3", 24, 35, 59,3,1)
person(3) ("NAME4", 1, 11, 12,4,5)
person(4) ("NAME5", 0, 22, 22,5,4)
I'm using this last column to define the order in which I'm displaying this array. But I need to be able to keep track of the original position (the second to last column).
Right now I'm using the following code:
Code:
Dim Pos1 As Integer
Dim Pos2 As Integer
For i = 0 To (UBound(Person) - 1)
'Previous Positions
Person(i, 4) = Person(i, 5)
For j = i To UBound(Person)
If CInt(Person(i, 3)) < CInt(Person(j, 3)) Then
Pos1 = CInt(Person(i, 5))
Pos2 = CInt(Person(j, 5))
' New Positions
Person(i, 5) = Pos2
Person(j, 5) = Pos1
End If
Next
Next
Comment