Array keys oddity?

J. Landman Gay jacque at hyperactivesw.com
Fri Jun 5 11:55:34 EDT 2009


DunbarX at aol.com wrote:
> OK, just started playing with arrays, and as usual stopped cold after 5 
> minutes.
> 
> I have a card with a "field 1" and button containing the following script:
> 
> on mouseup
>     put "" into fld 1
>     repeat with y = 1 to 10
>        put y & "-" & random(99)   into line y of tArray
>     end repeat
>     put tArray & return into fld 1
>     split tArray with return and "-"
>     put the keys of tArray   after   fld 1
> end mouseup
> 
> The normal (not array) variable is as advertised. The keys always have the 
> form:
> 
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 10
> 9
> 
> It gets much worse if you increase the number of elements. Only if I limit 
> myself to nine keys is this OK; as soon as you get a two digit key, all hell 
> breaks loose. This has to be me and my understanding of what the keys 
> really are. I tried to make as accessable a first array as I could, and as usual, 
> well, anyway, I can't wait to see...

The keys of an array are returned according to an internal engine hash 
order. They will virtually never be in the same order in which they were 
created. If order is important, you need to get the keys and then sort them.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list