Option menu query.

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
CAsba
Posts: 431
Joined: Fri Sep 30, 2022 12:11 pm

Option menu query.

Post by CAsba » Tue Aug 05, 2025 12:15 pm

Hi all,
I'm trying to give the user the option of a date in the current year or the year after the current year. So, he clicks on button 'YEAR' and chooses a year, either 2025 or 2026. In the future of course, the years might be 2027 and 2028. The script must make reference to the current year. I have the current year in fld "temp" and the following year in fld "temp2", also in variables 'thisyear' and 'nextyear' . Is it possible to introduce either the variables or the fields to an option menu ? or is there an easier way to present the user with choosing a date either in the current year or the next year ? Any ideas ?

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

Re: Option menu query.

Post by Klaus » Tue Aug 05, 2025 12:48 pm

Hi CAsba,

not sure if LC comes with a calendar widget, but here is a free and highly customizable calendar widget from the famous bn:
<viewtopic.php?f=9&t=39225&hilit=Calendarius>
Scroll a bit down for the download URL. Hope that helps!


Best

Klaus

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

Re: Option menu query.

Post by dunbarx » Tue Aug 05, 2025 2:27 pm

CAsba.

Calendar widgets aside, the selection of a date is automatically handled by LC without issue. In other words, LC does not care what date you want to process.

As for your question, put this into the script of an option menu:

Code: Select all

on mouseEnter
   convert the date to dateItems
   put item 1 of it into currentyear
   put currentyear + 1 into nextYear
   put currentyear & return & nextYear into me
end mouseEnter
Now that button will always show the current year and the following year, forever.

Craig

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

Re: Option menu query.

Post by CAsba » Tue Aug 05, 2025 5:16 pm

Thanks Klaus, thanks Craig.
Klaus, I'll try what you suggest..
Craig, the option menu I've been working with is of type 'on menuPick pitemname'. I tried putting your code into it, but there was an error message.

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

Re: Option menu query.

Post by dunbarx » Tue Aug 05, 2025 5:55 pm

CAsba.

An option menu is just a button. My code has to go intact into the button script.

A separate handler can be a "menuPick" handler. "MenuPick" is a message sent to the button when a menuItem is chosen from the pulldown options. That is where you would act on the users choice.

Do you see? My handler loads the values available for selection, and will update forever. The other deals with the user choice:

Code: Select all

on menuPick pItemName
if pItemName = "2025" then answer "A good year" else answer "Next year already?"
...
Craig

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

Re: Option menu query.

Post by CAsba » Wed Aug 06, 2025 2:16 pm

HI,
To report back, I solved my problem by showing 2 buttons showing as a two-item drop-down menu, the labels and scripts of the buttons having reference to current year and current year + 1. It offers the choices a menu would, and to the casual observer (the user) it's similar in appearance to the drop down menus for mth and day.
Thanks everyone for your interest.

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

Re: Option menu query.

Post by dunbarx » Wed Aug 06, 2025 3:54 pm

CAsba

Whatever works for you, and you got more experience along the way.

But isn't one button better than two?

Craig

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

Re: Option menu query.

Post by CAsba » Fri Aug 08, 2025 3:15 pm

Hi Craig,
I understand you, and I have done it that way, but in that way, 2025 is hard wired, it doesn't update itself to 2026 when the year changes; the essence of what I'm trying to do is that the menu items will just consist of 2 items, one being the current year, and the other being the current year + 1.

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

Re: Option menu query.

Post by FourthWorld » Fri Aug 08, 2025 4:41 pm

dunbarx wrote:
Tue Aug 05, 2025 2:27 pm

Code: Select all

   convert the date to dateItems
"the date" (or "date()") is a function, a value returned by the engine.

"convert" operates on containers.

I'd guess the error reported reflects a need to put the date into a variable first, and then run the convert operation on that variable.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: Option menu query.

Post by dunbarx » Fri Aug 08, 2025 5:51 pm

Casbah.

The "mouseEnter" handler I gave you automatically updates the contents of the button. That is what I meant by forever. Read it again.

Craig

Post Reply