Page 1 of 1

Repeat multidimensional array?

Posted: Fri Nov 22, 2013 7:03 am
by trenatos
I have a simple multi-dimensional array that I'm trying to repeat over.

I'm trying to figure out how to create buttons from the array.

It's a simple array: males[number]["name"] so nothing earthshattering there, but I can't figure out how to loop over it and pull the "name" each time.
I've added to this array by using a variation of put males[1]["bob"] for testing.

Could someone help me out?

Re: Repeat multidimensional array?

Posted: Fri Nov 22, 2013 8:23 am
by Simon
Hi trenatos,
For males[number]["name"]

Code: Select all

    repeat for each key tKey in males
       answer males[ tKey ][ "name" ]
    end repeat
Fun. :D
But that is not the same for:
put males[1]["bob"]

Simon

Re: Repeat multidimensional array?

Posted: Fri Nov 22, 2013 9:12 am
by trenatos
I have a bunch of these: males[1]["bob"]
males[2]["marcus"]
males[3]["anders"]

and so on, and need to go through and grab the value of each name, but I'm not sure how to figure out how many records there are, then I believe I could just loop through the records such as

repeat counter = 1 to (the magic number)
put males[counter][2] into a variable/create a button/copy to other variable/whatever
end repeat

Re: Repeat multidimensional array?

Posted: Fri Nov 22, 2013 9:20 am
by Simon
Then it's just:

Code: Select all

   repeat for each key tKey in males
       answer males[ tKey ]
    end repeat
The last bracket ["bob"] is not correct in your request.
errr... it says there is more info following?

Simon

Re: Repeat multidimensional array?

Posted: Fri Nov 22, 2013 12:59 pm
by Klaus
Hi trenatos,
trenatos wrote:I have a bunch of these: males[1]["bob"]
males[2]["marcus"]
males[3]["anders"]

and so on, and need to go through and grab the value of each name, but I'm not sure how to figure out how many records there are, then I believe I could just loop through the records such as

repeat counter = 1 to (the magic number)
put males[counter][2] into a variable/create a button/copy to other variable/whatever
end repeat
do this to retrieve your "magic number:

Code: Select all

...
pu the keys of male into tMaleKeys
put the num of lines of tMaleKey into theMagicNumber
repeat with counter = 1 to theMagicNumber
...
Best

Klaus

Re: Repeat multidimensional array?

Posted: Fri Nov 22, 2013 6:22 pm
by trenatos
Klaus, I haven't tested the code yet, but that looks exactly like what I need.
I knew it'd be something simple, but not able to figure it out.

Thank you!

Re: Repeat multidimensional array?

Posted: Fri Nov 22, 2013 6:29 pm
by Klaus
Hi trenatos,

my pleasure :D

But if you want SPEED, use Simon's suggestion:
...
repeat for each key tKey in male
## do something with: male[tKey]
end repeat
...
If applicable in your case.


Best

Klaus