Page 1 of 1

Can you sort an array

Posted: Tue Nov 03, 2009 8:14 am
by el_stupido
Can you use the sort command on an array?

or is the a separate sort command for arrays?

or do I have to pass the array to a variable then sort it???????????

Just seeing if I can cut corners...


:twisted:

Posted: Tue Nov 03, 2009 10:35 am
by Mark
Dear el_stupido,

You can't sort an array, because it has no order. You can put the keys of an array into variable and sort them:

Code: Select all

put the keys of myArray into myVar
sort lines of myVar
repeat for each line myLine in myVar
  put myVar[myLine] into myFoo
  -- do something with myFoo
end repeat
If this isn't what you want, then you will have to combine the array and deal with it as an ordinary variable.

Best,

Mark

Posted: Tue Nov 03, 2009 2:59 pm
by el_stupido
I meant the values stored in the array say for instance 'sort the values of this array in ascending order.

I'm guessing no command for this though. Looks like I have to code the sort the long way :(

Posted: Wed Nov 04, 2009 2:09 am
by BvG
you can do it using split and combine (make sure to use delimiters that fit your data):

Code: Select all

combine theArray by return and comma
sort theArray by item 2 of each
--do stuff for which you need it sorted
split theArray by return and comma

Re: Can you sort an array

Posted: Sun Nov 29, 2009 10:12 am
by skindoc4
I also discovered this property, rather lack of a property, the hard way when my database fields failed to line up the way I expected them to. I sort the keys as a reflex now.

Alex