sort array ?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
link76
Posts: 99
Joined: Fri Nov 04, 2011 1:52 pm

sort array ?

Post by link76 » Mon Jun 18, 2012 10:43 am

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

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: sort array ?

Post by shaosean » Mon Jun 18, 2012 11:17 am

Might be easier to do the sorting in your DB query using the ORDER BY clause..

link76
Posts: 99
Joined: Fri Nov 04, 2011 1:52 pm

Re: sort array ?

Post by link76 » Mon Jun 18, 2012 11:30 am

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"

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: sort array ?

Post by bn » Mon Jun 18, 2012 12:02 pm

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

Post Reply