Page 1 of 1

sort array ?

Posted: Mon Jun 18, 2012 10:43 am
by link76
Hello,
how can I sort the array in ascending order?

Code: Select all

....
repeat until revQueryIsAtEnd(theCursor)

add 1 to i
put distanza(myvalue) into totale[i]

revMoveToNextRecord theCursor
end repeat

....
thanks

the result:

Code: Select all

totale[1] = "21344.4"
totale[2] = "344.7"
totale[3] = "11344.5"
totale[4] = "91344.2"
I like this result:

Code: Select all

totale[1] = "344.7"
totale[2] = "11344.5"
totale[3] = "21344.4"
totale[4] = "91344.2"
thanks

Re: sort array ?

Posted: Mon Jun 18, 2012 11:17 am
by shaosean
Might be easier to do the sorting in your DB query using the ORDER BY clause..

Re: sort array ?

Posted: Mon Jun 18, 2012 11:30 am
by link76
shaosean wrote:Might be easier to do the sorting in your DB query using the ORDER BY clause..
I can not order for databases,
I have to order the values ​​obtained with the function, in the variable "totale"

Re: sort array ?

Posted: Mon Jun 18, 2012 12:02 pm
by bn
Hi Link,
you could try something like this:

Code: Select all

 combine totale by return and comma
   sort totale numeric ascending by item 2 of each
   put totale
you can not sort the array by its content directly. You could sort the keys of the array but that is not what you want.
Once you combine an array it is not an array anymore, if you want to preserve the array you could either splt the list you get from combine or do the combine on a copy of totale

Kind regards
Bernd