Page 1 of 1

Array help

Posted: Wed Jul 12, 2017 12:46 am
by edwardeddyus
I created an array

Code: Select all

put "Purpose Data"  into ar[1]["purpose" ]
   put "Dose Data" into ar[2]["dose" ]
   put "Side Effects Data"  into ar[3]["side effects" ]
   put "Emergency Conditions Data" into ar[4]["Emergency cond" ]
   put "Abuse Potential Data" into ar[5]["Abuse Potential" ]
   put "Cautions Data" into ar[6]["Cautions" ]
but when I run

Code: Select all

   local counter
   put 0 into counter
   repeat for each key tKey in ar
      repeat for each key sKey in ar[tKey]
         //put the number of fields of group ar[tKey][sKey] into tCount
     end repeat
     put counter+1 into counter
    put sKey into btnnms[counter]
     answer counter & "=" & sKey
   end repeat
I get

6=Cautions
1=purpose
2=dose
3=side effects
4=Emergency cond
5=Abuse Potential

Why am I getting the last item in the array first?

Re: Array help

Posted: Wed Jul 12, 2017 1:40 am
by FourthWorld
Associative arrays have no inherent sense of order. They are name-value pairs, regardless whether the name is numeric or alphanumeric.

If you need to sort keys or other values obtain from an array use the sort command.

Re: Array help

Posted: Wed Jul 12, 2017 3:19 am
by [-hh]
Your script is correct and works here (both parts in one "MouseUp").
Probably you didn't reset the counter to 0 as above when you got the wrong result?