# Sorting a two dimensional array

## Recommended Posts

I have an array set up like this

Dim \$targets[4][unknown]

On the \$targets[3][\$i] in the array, a bunch of numbers are stored.

I want to sort the array so that it gets sorted with those numbers going from smallest to biggest.

I know it is done with _Arraysort, but I am not sure how to set it up so that it does what I want it to.

##### Share on other sites

I have an array set up like this

Dim \$targets[4][unknown]

On the \$targets[3][\$i] in the array, a bunch of numbers are stored.

I want to sort the array so that it gets sorted with those numbers going from smallest to biggest.

I know it is done with _Arraysort, but I am not sure how to set it up so that it does what I want it to.

I've only ever done this with a 1 dim array, you can mod this if you like:
```Func _ArraySortNum(ByRef \$nArray, \$Ascending = 0, \$Start = 1)
If \$Ascending <> 0 And \$Ascending <> 1 Then Return SetError(1)
For \$i = \$Start To UBound(\$nArray) - 2
Local \$SE = \$i
If \$Ascending = 0 Then
For \$x = \$i To UBound(\$nArray) - 1
If Number(\$nArray[\$SE]) < Number(\$nArray[\$x]) Then \$SE = \$x
Next
Else
For \$x = \$i To UBound(\$nArray) - 1
If Number(\$nArray[\$SE]) > Number(\$nArray[\$x]) Then \$SE = \$x
Next
EndIf
Local \$HLD = \$nArray[\$i]
\$nArray[\$i] = \$nArray[\$SE]
\$nArray[\$SE] = \$HLD
Next
EndFunc```

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

Im sure _Arraysort can do it in one line though.

I have done it before... But I forget how to set it up.

##### Share on other sites

Im sure _Arraysort can do it in one line though.

I have done it before... But I forget how to set it up.

Unless they fixed it, I don't think it worked with numbers past 9 ...ie... 10 11

1

2

3

4

5

6

7

8

9

10

and used _ArraySort() you got

1

10

2

3

4

5

6

7

8

9

Which is why I made the _ArraySortNum()

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

Ill possible come back and try to mod your code later on, its almost 6am here with no sleep : /

Thus the looking for easy answers.

##### Share on other sites

Ill possible come back and try to mod your code later on, its almost 6am here with no sleep : /

Thus the looking for easy answers.

show some of your code so we can help.

You can do it with the included _ArraySort() but need to remember to store the values as numbers not as string ..

Live for the present,
Dream of the future,
Learn from the past.

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...