Sorting an Array Based on another array

I have two arrays

aNames() – string
aRank() --integer

Given
aNames(0)=Mars
aNames(1)=Venus
aNames(2)=Jupiter
aNames(3)=Pluto //Yes it is!

aRank(0)=1
aRank(1)=2
aRank(2)=4
aRank(3)=3

I wish to sort aNames() by the values of aRank() to end up with:

aNames(0)=Mars
aNames(1)=Venus
aNames(2)=Pluto
aNames(3)=Jupiter

Is there an easy way to do this?

Try SortWith: http://documentation.xojo.com/index.php?title=Sortwith&oldid=43396

Check the Xojo documentation for array.SortWith

We tried that:

Dim aNames() as string Dim aRank() as integer aNames = Array("Mars", "Venus", "Jupiter", "Pluto") aRank= Array(1,2,4,3) aNames.SortWith(aRank)

But it comes out:
aNames(0)=Jupiter
aNames(1)=Mars
aNames(2)=Pluto
aNames(3)=Venus

aRank.SortWith(aNames)