Adding items to button question

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
tasdvl9
Posts: 94
Joined: Fri Dec 06, 2013 3:55 am

Adding items to button question

Post by tasdvl9 » Tue Apr 22, 2014 6:18 pm

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!

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Adding items to button question

Post by magice » Tue Apr 22, 2014 6:38 pm

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.

tasdvl9
Posts: 94
Joined: Fri Dec 06, 2013 3:55 am

Re: Adding items to button question

Post by tasdvl9 » Tue Apr 22, 2014 7:03 pm

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?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: Adding items to button question

Post by dunbarx » Tue Apr 22, 2014 7:23 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Adding items to button question

Post by jacque » Wed Apr 23, 2014 8:49 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply