I might be misunderstanding but trying to use sort with to order a second array like this but the surfer order never changes
[code]Var surferorder() As Text = Array(“Surfer1”, “Surfer2”, “Surfer3”, “Surfer4”)
Var totals() As double = Array(Surfer1Total, Surfer2Total, Surfer3Total, Surfer4Total)
[code]dim n() as integer =array(0,10,5,2,4)
dim s() as string = array(“zero”,“ten”,“five”,“2”,“four”)
//print the original data
print("unsorted “+join(s,”, "))
//sort using the values in n
n.sortwith(s)
print("sorted “+join(s,”, "))[/code]
Your n array needs to be a simple class such as integer, double or string(if you want it alphabetically)
Your s array can be anything, so long as the order of s is the same as n - i.e. they are added in the same (unsorted) order.
Output:
unsorted zero, ten, five, 2, four
sorted zero, 2, four, five, ten
[quote=494743:@Martin Fitzgibbons]I might be misunderstanding but trying to use sort with to order a second array like this but the surfer order never changes
[code]Var surferorder() As Text = Array(“Surfer1”, “Surfer2”, “Surfer3”, “Surfer4”)
Var totals() As double = Array(Surfer1Total, Surfer2Total, Surfer3Total, Surfer4Total)
totals.Sort
surferorder.SortWith(totals)
MsgBox "Winner "+surferorder(surferorder.LastRowIndex)
[/code][/quote]
Youre calling it backwards. You need to use SortWith on the array you want to sort with:
totals.SortWith(surferOrder)
The reason is that SortWith can take more than one array so you can do multiple at the same time.
Probably not what I need. I thought I could sort the scores in into ascending order and then Sortwith would apply that same sorted order to the name array so the scores matched the names??