Option menu tagged to array

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
saviour
Posts: 26
Joined: Wed Feb 05, 2014 5:11 am

Option menu tagged to array

Post by saviour » Wed Nov 11, 2015 6:14 pm

Hi guys,,

Please need some help. I dont know if it is possible or not. But lets see.

I have some data array in field "mylist" in following manner:

xx,xxx
yy,yyy
zz,zzz

I am able to populate option menu ( with xx or yy or zz);

Now, Is it possible to having either option selected, retreive related data as in array like xx to retrieve xxx.....

Thanks....
Last edited by saviour on Fri Nov 13, 2015 3:22 pm, edited 1 time in total.

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

Re: Option menu tagged to array

Post by dunbarx » Wed Nov 11, 2015 8:06 pm

Hi.

I assume you do not want to see the "related" data in the actual button, that is, you want to see "xx" but "get" "xxx". Is this true?

If so, load the array into a custom property, and grab the associated data, since it is already built. A "key" would be chosen from the option menu and the associated element pulled from the property. Do you know how to do that?

Craig Newman

saviour
Posts: 26
Joined: Wed Feb 05, 2014 5:11 am

Re: Option menu tagged to array

Post by saviour » Thu Nov 12, 2015 2:17 am

Thanks for that.. :D

Yes, I want related data 'XXX' in another custom variable or field if key "XX' chosen in the menu. Please guide me :oops:

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

Re: Option menu tagged to array

Post by jacque » Thu Nov 12, 2015 5:51 pm

You can shorten the handler a bit:

Code: Select all

on preopencard
    put fld "MyList" into gMyArray
    split gMyArray by cr and comma
   set the text of btn "listIn" to the keys of gMyArray
end preopencard
The do what Craig said, use the selection as the array key to get the value.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Option menu tagged to array

Post by dunbarx » Thu Nov 12, 2015 7:33 pm

OK. I am going to do this for you, but you have to examine each line (there are only a few) of the following handlers and tell me what they do. On a new card, make a field, standard button, and an option button. Name the option button "XYZ".

In the field, put your:

Code: Select all

xx,xxx
yy,yyy
zz,zzz
In the script of the standard button:

Code: Select all

on mouseUp
     put fld 1 into gMyArray
     split gMyArray by cr and comma
     set the text of btn "XYZ" to the keys of gMyArray
   set the relatedData of btn "XYZ" to gMyArray
end mouseUp
In the script of the option button:

Code: Select all

on menuPick pItemName
   get the relatedData of me
   answer it[pItemName]
end menuPick
A little Jacque, a little me. I expect comments.

Craig

saviour
Posts: 26
Joined: Wed Feb 05, 2014 5:11 am

Re: Option menu tagged to array

Post by saviour » Fri Nov 13, 2015 3:31 pm

Thanks a lot guys.

Your suggestions are like lightbulb to me. I am able to do it by putting the menu selection in another variable and finally feeding it to the array.

put gMyArray[tOption] into tName
Answer tName

Thanks again.

Post Reply