Populate Option Menu from Array [Solved]

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

antrax13
Posts: 39
Joined: Mon Jun 01, 2015 11:38 am

Populate Option Menu from Array [Solved]

Post by antrax13 » Mon Jun 01, 2015 11:46 am

Hi I have an array that is coming from DB so every time it will be different.

When array is created I need to populate Option Menu button with these values.

My Code is:

Code: Select all

 repeat for each element title in tColumnTitles
         --answer title 
         put the text of btn "omLocation" to title
 end repeat
it will set the value always to last element in array and I would like to see all elements to be available/visible in Option Menu dropdown not just the last one

so IE if array contains Peter,John,Martin

I want to see all options in dropdown not just Martin
Last edited by antrax13 on Tue Jun 02, 2015 9:31 am, edited 1 time in total.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Populate Option Menu from Array

Post by jmburnod » Mon Jun 01, 2015 12:18 pm

Hi,
What about this ?

Code: Select all

on buildMyMenu
   put "Peter,John,Martin" into tColumnTitles
   replace "," with cr in tColumnTitles
   set the text of btn "omLocation" to  tColumnTitles
end buildMyMenu
Best regards
Jean-Marc
https://alternatic.ch

Klaus
Posts: 14190
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Populate Option Menu from Array

Post by Klaus » Mon Jun 01, 2015 1:15 pm

Hi antrax13,

1. welcome to the forum! :D

2. That depends on your Array! What format does your array have exactly?
e.g. like this:
tColumTitles[1]["Peter"]
tColumTitles[2]["John"]
tColumTitles[3]["Martin"]
...
?


Best

Klaus

antrax13
Posts: 39
Joined: Mon Jun 01, 2015 11:38 am

Re: Populate Option Menu from Array

Post by antrax13 » Mon Jun 01, 2015 1:39 pm

Code: Select all

 
local lTest
      repeat for each element lTitle in tColumnTitles
         put lTitle & cr after lTest
      end repeat
      set the text of btn "omLocation" to lTest
this did the trick and now all options are visible in option menu button

Klaus
Posts: 14190
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Populate Option Menu from Array

Post by Klaus » Mon Jun 01, 2015 3:04 pm

Glad we could help! :D

CAsba
Posts: 431
Joined: Fri Sep 30, 2022 12:11 pm

Re: Populate Option Menu from Array [Solved]

Post by CAsba » Mon Nov 07, 2022 3:13 pm

Where is the code put ?

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Populate Option Menu from Array [Solved]

Post by jmburnod » Mon Nov 07, 2022 3:33 pm

Hi CAsba,
Where is the code put ?
set the text of...
Best
Jean-Marc
https://alternatic.ch

CAsba
Posts: 431
Joined: Fri Sep 30, 2022 12:11 pm

Re: Populate Option Menu from Array [Solved]

Post by CAsba » Mon Nov 07, 2022 3:40 pm

Hi Jimburnod
Sorry, I don't get it. I have a csv array in a field, consisting of current year, current year less 1, less 2, etc., that I want to put as a list of choices for the user. How best to populate the menu choices space ?

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

Re: Populate Option Menu from Array [Solved]

Post by dunbarx » Mon Nov 07, 2022 4:14 pm

CAsba.

So you do not have an "array", but just text in a field. Be careful, since "array" means something very specific in LiveCode.

Is your data comma delimited, as "csv' implies? if so, you can create a cascading menu to display the data.

Craig

CAsba
Posts: 431
Joined: Fri Sep 30, 2022 12:11 pm

Re: Populate Option Menu from Array [Solved]

Post by CAsba » Mon Nov 07, 2022 4:38 pm

Hi Craig,
yes, it is comma seperated, in a field. I guess I don't know what an array is, then...
So, how would I proceed to set up a cascading, or other, drop down menu, with the values in the field as choices ?

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

Re: Populate Option Menu from Array [Solved]

Post by dunbarx » Mon Nov 07, 2022 4:45 pm

It occurs to me, do you know how to create a hierarchal (cascading) menu? I ask because I am not sure that an option menu is a good choice. Each of the four menu buttons acts a little differently. Read about this in the User Guide, page 176.

Check out this stack, which has all four menu buttons. Play with it. If you need more submenus, try to make them, and come back here if you need help.
MenuTest.livecode.zip
(1.27 KiB) Downloaded 148 times
Craig

CAsba
Posts: 431
Joined: Fri Sep 30, 2022 12:11 pm

Re: Populate Option Menu from Array [Solved]

Post by CAsba » Mon Nov 07, 2022 5:08 pm

Hi Craig,
True, I know very little about the various menu possibilities. But, I used the option type successfully to allow the user to choose the day and the month of the date required. The difference with the year is that the current year has to be one of the choices, with the other choices being current year -1, -2, -3 etc. So, it's a dynamic choice, which will change every year, unlike the day and month choices. So, instead of manually populating the option menu, as I did with day and month, it is necessary to get the current year listed as a reference for the choices.
So, the situation is, to recap, the option menu appears to offer the required facility, as shown in the month and year menus, but I need a way to insert, as choices, a list of years headed by the current year. I have read quite a lot about setting up menus but nothing to enlighten me re this issue.
Hoping you can help.

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

Re: Populate Option Menu from Array [Solved]

Post by dunbarx » Mon Nov 07, 2022 7:42 pm

Keep talking.

This is simple. The keyword "dateItems" allows full control of dates and times. One can add or subtract values from the several parts of that gadget, and obtain any other date and time. Please experiment with this until you have it down. It is not complicated and actually fun to do so.

You will soon see that one can "convert" (a command), for example, today's date to "dateItems". When you get that value, add, say, 50 to the third item. (the "day of the month"). Once you do that, convert back to the long date. You will see that all the math has been done for you and the new date, over seven weeks later, is properly formatted. With that tool you can then create the list you require.

Get going, and if you need more help, come back.

Craig

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

Re: Populate Option Menu from Array [Solved]

Post by jacque » Tue Nov 08, 2022 7:12 pm

Since you only need the year, you can get that from the date function. Either parse it out from the date or convert the date to dateitems and get item 1 of that.

After you know the current year it is easy to subtract 1 from it as many times as you need. Keep the years in a return-delimited list. When the list is ready:

Code: Select all

set the text of button "years" to tList 
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10045
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Populate Option Menu from Array [Solved]

Post by FourthWorld » Tue Nov 08, 2022 7:34 pm

This thread is conceptually similar; would it be helpful to future readers if I merged this one with that?

https://forums.livecode.com/viewtopic.php?f=7&t=37440
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply