Page 1 of 1

Creating/Populating Associative Array[Solved]

Posted: Wed Aug 26, 2015 1:58 pm
by antrax13
Hi All,
I ve been trying for a while with no success to create associative array
When I am looping via data grid I am getting these values => id and description for each loop
I will get this information for every single loop

Code: Select all

9 ----------- Description Test
1 ----------- Description Test Test
3 ----------- Description Test Test Test
so my code for this is

Code: Select all

repeat for each element e in AvailableArray
   answer e["id"]&"--------------"&e["description"]
 -- HERE needs to be a code to create bottom array
end repeat 
but I am not able to construct array that looks exactly like the one I am showing below

Code: Select all

Array
..	[1] => Array
..	.	[id] => 9
..	.	[description] => Description Test
..	[2] => Array
..	.	[id] => 1
..	.	[description] => Description Test Test
..	[3] => Array
..	.	[id] => 3
..	.	[description] => Description Test Test Test
Reason why I need this is that I have data grid where I can select rows and when I select these rows I need to populate another grid with selected rows.

Now Imagine I will select row with ID 9 and 3 I need to create an array that will look like this

Code: Select all

Array
..	[1] => Array
..	.	[id] => 9
..	.	[description] => Description Test
..	[2] => Array
..	.	[id] => 3
..	.	[description] => Description Test Test Test

Re: Creating/Populating Associative Array

Posted: Wed Aug 26, 2015 2:07 pm
by dunbarx
Hi.

Make a button and a field. In the button script:

Code: Select all

on mouseup
   put "" into fld 1
   repeat with y = 1 to 10
      put 2 * y into tArray[y}
   end repeat
 answer the keys of tArray
   
   set itemdel to "-"
   combine tArray with return and "-"
   sort tArray numeric by item 2 of each
   put tArray into  fld 1
end mouseup
This gives a few numbers and their doubles.

Now this in the button script:

Code: Select all

on mouseUp
   put "" into fld 1
   repeat 100
      put any word of "zz aa bb ss dd" & space after temp
   end repeat
   put temp into line 1 of fld 1
   repeat for each word tWord in temp
      add 1 to tWordCount[tWord] --ADD 1 TO THE ELEMENT OF A KEY
   end repeat
   answer tWordCount["aa"]
end mouseup
This makes a bunch of random words, and counts how many times "aa" appears.

Practice, practice...

Craig Newman

Re: Creating/Populating Associative Array

Posted: Wed Aug 26, 2015 2:15 pm
by antrax13
OK got what I need here is the code that was needed :)

Code: Select all

   put 1 into counter
   repeat for each element e in AvailableArray
      put e["id"] into testArray[counter]["id"]
      put e["description"] into testArray[counter]["description"]
      add 1 to counter
   end repeat
Thanks to myself :D