Get date from user

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

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

Get date from user

Post by CAsba » Fri Oct 21, 2022 11:18 am

Hi,
I need to to get the start date of a VAT period from the user, and I'm wondering what is the easiest way.
One way I'm considering is to have three drop down menus, day, month and year and convert the results to a date.
Another way - I've just downloaded a calendar control add-on for Livecode which is now on my desktop, but I have no idea how to get it into LC, so unless I can do that, it's a non-starter.
Or there might be another, obvious way, but I've scoured the internet and not found anything - does anyone have any advice to offer, please ?

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

Re: Get date from user

Post by Klaus » Fri Oct 21, 2022 11:42 am

Hi CAsba,

so you have a file named "com.livecode.widget.calendar.lce" on your desktop, right?
Now you need to install it with the help of LC, do like this to get it into LC:
1. Menu: Tools: Extensions Manager
2. In that window click the little PLUS sign in the top right corner
3. A file dialog appears, select that "com.livecode.widget.calendar.lce" file on your desktop
4. LC does the rest
That's it, then you will see a new icon in your tool palette, the calendar!

Best

Klaus

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

Re: Get date from user

Post by CAsba » Fri Oct 21, 2022 12:08 pm

Many thanks, Klaus.
I've got it on the card but it is not accepting the script I copied and pasted

on dateChanged pDate
get the selectedDate of widget
set the selectedDate of widget to pDate
end dateChanged

it reads
Widget "Calendar": compilation error at line 2 (Expression: bad factor), char 8

Any ideas ?

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

Re: Get date from user

Post by Klaus » Fri Oct 21, 2022 12:11 pm

Add the NAME of your widget!

Code: Select all

...
get the selectedDate of widget "your new calendar widget name here, SIR!"
...

Code: Select all

on dateChanged pDate
  ## If you do not use or need IT at this point, then you don't need this line!
  get the selectedDate of widget xyz
  ## !??
  set the selectedDate of widget xyz to pDate
end dateChanged
CODE TAGS, please! 8)

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

Re: Get date from user

Post by CAsba » Fri Oct 21, 2022 12:42 pm

Working perfectly now, many thanks guys !

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

Re: Get date from user

Post by Klaus » Fri Oct 21, 2022 12:54 pm

CAsba wrote:
Fri Oct 21, 2022 12:42 pm
...many thanks guys !
I am only ONE! :-D

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Get date from user

Post by richmond62 » Fri Oct 21, 2022 1:29 pm

I am only ONE!
-
coatTags.jpg
coatTags.jpg (4.67 KiB) Viewed 4406 times
Coat Tags, Please. :D

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

Re: Get date from user

Post by CAsba » Tue Nov 01, 2022 1:11 pm

Hi Klaus (as you helped me a month ago on this),
Unfortunately the calendar widget proved to be an unreliable solution, as this morning I found the widget to be "greyed out" that is, it was just a grey rectangle. i dcon't know what caused this, but I'm glad it happened before the project went live.
So, I'm back to looking for how to get the start date from the user.
I've set up three drop-downs, day, mth and yr, and got the output into a field as 3/7/2017, but this text has to be converted into a date. The dictionary shows an example of a convert script but the text to be converted was surrounded by quotes. I've been trying to add quotes to the text in the field but without success.

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

Re: Get date from user

Post by Klaus » Tue Nov 01, 2022 1:39 pm

Hi CAsba,
CAsba wrote:
Tue Nov 01, 2022 1:11 pm
Hi Klaus (as you helped me a month ago on this),...
yes, my memory still reaches so far! 8)

No idea what your problem is, this -> 3/7/2017 IS in fact a valid date?
What do you want to convert additionally?

Best

Klaus

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

Re: Get date from user

Post by dunbarx » Tue Nov 01, 2022 1:52 pm

We can work out the date thing, but what has happened to the widget?

CAsba, can you post a screen shot of this gray rectangle?

And I have never used a widget. Can one ask for "the number of widgets", to make sure there still is one?

Craig

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

Re: Get date from user

Post by CAsba » Tue Nov 01, 2022 1:55 pm

Well, it LOOKS like date, but I tried to verify it as such by trying
add 2 to the item 3 of fieldannounce2
with no effect. Later the programme will have to count from the date, so I need to know the text that looks like a date will work like a date.

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

Re: Get date from user

Post by Klaus » Tue Nov 01, 2022 1:59 pm

Code: Select all

add 2 to the item 3 of fieldannounce2
What is this supposed to do?
Is "fieldannonce2" a variable?
Did you set the itemdelimiter to / first?

Something like this does work however:

Code: Select all

...
convert "3/7/2017" to dateitems
put it
## -> 2017,3,7,0,0,0,3
...
So this is a valid and correct date!

P.S. Did you check the stacks here:
http://www.hyperactivesw.com/revscriptc ... ences.html
?
There is also one about "Date and Time"!

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

Re: Get date from user

Post by CAsba » Tue Nov 01, 2022 2:17 pm

Hi,
fieldannounce2 is a field
Did you set the itemdelimiter to / first? No, I didn't know about it, I will try that
I just found the stacks you mentioned. There is a lot to read.. I will do that.
I thought it was to increment the year by 3 - maybe I'm wrong.
Yes I saw the example you gave that works,; my prob is that I can't get the text of the date in quotes.
Unfortunately, I'm not going tyo be bale to with the projerct for a week, but when I coime back this issue will be my first priority adn I will reade up and contact you again, then, if necessary.
Many thanks so far.

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

Re: Get date from user

Post by Klaus » Tue Nov 01, 2022 2:27 pm

Hi CAsba,
CAsba wrote:
Tue Nov 01, 2022 2:17 pm
Hi,
fieldannounce2 is a field
Did you set the itemdelimiter to / first? No, I didn't know about it, I will try that
OK, then
1. use QUOTES around the fields name.
2. DEFAULT itemdelimiter is a COMMA,so you need to set it to whatever you need first
3. However you cannot add something to a date like you were trying to to.
4. Convert your date to DATEITEMS, add years, months, days etc. and then convert it back to data.
Example, add 3 years to a date:

Code: Select all

...
## Contents of fieds are in fact strings, so no need to care about QUOTES here!
put fld "fieldannounce2" into tDate

## First convert to dateitems:
convert tDate to DATEITEMS
## 2017,3,7,0,0,0,3

## YEARS are the first item in dateitems:
add 3 to item 1 of tDate
convert tDate to date
answer tDate
## -> 3/7/2020
...
Best

Klaus

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

Re: Get date from user

Post by dunbarx » Tue Nov 01, 2022 4:25 pm

CAsba.

If "fieldAnnounce2" is a field then you have a syntax error. You cannot

Code: Select all

add 2 to the item 3 of fieldannounce2
rather:

Code: Select all

add 2 to item 3 of field "fieldannounce2"
Do you see the difference? And, as Klaus says, you MUST be aware of the current itemDelimiter as each line of code is executed. That property can be set as often as you wish, but you have to keep track of its current state.

It is a matter of style, and LC does not seem to care, but try to not use keyword "the" except when identifying a property. So you do not need it, as per my code snippet. In your case here, you would include "the" when dealing with properties:

Code: Select all

set the itemDelimiter to "/"
Craig

Post Reply