Page 1 of 1

Adding items to button question

Posted: Tue Apr 22, 2014 6:18 pm
by tasdvl9
Hi All,

I'm having issues trying to fill my button with the data which is in my array.

Basically I have an array of 10 items.
When I use the combine command I notice the order is different than what is in the array.

My code snippet is such:

repeat for each line myKey in it
put word 1 of myKey into varDataA2Tmp[myTempCntr]
add 1 to myTemoCntr
end repeat

combine varDataA2Tmp using return
put "ALL" & cr & varDataA2Tmp into button "cmbDataTest"

When I click on the button the items are out of order.
Any advice?

Thanks!

Re: Adding items to button question

Posted: Tue Apr 22, 2014 6:38 pm
by magice
A computer orders numbers the same way it orders letters. So, 10 would be placed between 1 ans 2. This is probably what is causing the problem. I have worked around this problem in the past by starting my array keys at 101 instead of 1.

Re: Adding items to button question

Posted: Tue Apr 22, 2014 7:03 pm
by tasdvl9
Thanks for the response.

The problem seems to happen when I use the combine command.

I's there a way to use the combine and sort commands without having the line numbers displayed in the button?

Re: Adding items to button question

Posted: Tue Apr 22, 2014 7:23 pm
by dunbarx
Hi.

Livecode's arrays are purely associative. They do not try to maintain sort order through the process of creation (with "split") or restoration (with "combine").

You must sort outside the array by hand. So to your point, yes, combine and then sort.

That said, if you watch an array in the debugger, you will find it is "mostly" sorted. But that is not something you should rely on at all. I have always just found that fact to be interesting. I would have thought the array would be virtually random with respect to its keys.

Craig Newman

Re: Adding items to button question

Posted: Wed Apr 23, 2014 8:49 pm
by jacque
The IDE sorts the array in the variable watcher for you. As you say, that isn't how it really looks in a variable so don't rely on it.