| View previous topic :: View next topic |
| Author |
Message |
jwfv Valued Contributor

Joined: 19 Mar 2002 Posts: 422 Location: Beaufort, SC
|
Posted: Wed Jun 11, 2003 1:21 pm Post subject: Help on valid dates? |
|
|
I have searched the forum and haven't found this topic. Any help is appreciated:
I have an edit box where the user enters a date. Then, when the data is saved, that date is saved in a database.
How can I check to make sure the date is valid before saving? I could do it either at the time it is saved, or before they exit the edit box.
I can't figure out how to use @datetime() to make sure the date is valid and not something like:
13/14/15
Thanks!
(PS - An alternative solution would be I guess to check that the date is X number of days away from today's date? - The date they will enter should always be within a couple of weeks of today's date .....) |
|
| Back to top |
|
 |
DW Contributor

Joined: 21 Mar 2003 Posts: 175 Location: UK
|
Posted: Wed Jun 11, 2003 1:37 pm Post subject: |
|
|
Im not really sure but couldnt you parse the three sections of the dateand then check it?
Example being, user enters 10/03/03
you could have your program take the days which would be 10, then the month which is 03, and finally the year, also 03.
after cutting up all the sections you could check each one.
Just a suggestion but i think it would work.
Maybe someone round here can show you what I have said in code form.
Hope that helps some. |
|
| Back to top |
|
 |
DW Contributor

Joined: 21 Mar 2003 Posts: 175 Location: UK
|
Posted: Wed Jun 11, 2003 1:49 pm Post subject: |
|
|
Im only a noob but would something like this do it?
Would need better checking routen.
| Code: |
:Init
rem this makes parse use / instead of default which is |
option fieldsep,/
:Main
DIALOG CREATE,DateCheck,-1,0,240,99
DIALOG ADD,EDIT,EDIT1,32,26,180,19
DIALOG ADD,BUTTON,BUTTON1,52,144,64,24,Check
DIALOG ADD,TEXT,TEXT1,16,26,,,Enter date (example 01/01/01)
DIALOG SHOW
:Evloop
wait event
goto @event()
:BUTTON1BUTTON
rem cuts up the date from edit1 and put it into %%day, %%month and %%year.
%%DATE = @dlgtext(edit1)
parse "%%day;%%month;%%year",%%DATE
rem tells you what you entered.
info the day is %%day@cr()the month is %%month@cr()and the year is %%year.
rem example check, this is just simple stuff.
rem im only a noob...
if @greater(%%day,31)
info not a valid day
end
goto evloop
:Close
exit
|
|
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Wed Jun 11, 2003 2:25 pm Post subject: |
|
|
Well I get an exception: invalid date/time error when using this code:
| Code: | if @ok(@datetime(mm/dd/yyyy, 13/14/1435))
info Valid Date
else
warn Invalid Date
end |
Unfortunately there's no way to process the error, even with ERRORTRAP.  _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
jwfv Valued Contributor

Joined: 19 Mar 2002 Posts: 422 Location: Beaufort, SC
|
Posted: Wed Jun 11, 2003 2:58 pm Post subject: valid date |
|
|
Thanks for the responses -
Yeah, I could break it up like in your example, DW - I may do that.
I was hoping for an elegant, one-line solution (of course.) But like FF shows in his example, checking @datetime on an invalid date just gives an error right off the bat.
Thanks for the help, though. I may modify the example parsing code and use that, if nothing else comes along. |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Thu Jun 12, 2003 3:26 pm Post subject: |
|
|
you could also use 3 drop down boxes (one for the days, one for the months and one for the years)...this way you don't have to worry about checking dates...the down side is that you need to set the number of days depending on the month selected (eg. february)
or you can use 3 spin boxes...
Serge _________________
|
|
| Back to top |
|
 |
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
Posted: Sun Jun 15, 2003 8:41 pm Post subject: |
|
|
| Also DLLs exist that have a datetime selection element (VDSOBJ 2?). |
|
| Back to top |
|
 |
jwfv Valued Contributor

Joined: 19 Mar 2002 Posts: 422 Location: Beaufort, SC
|
Posted: Sun Jun 15, 2003 8:48 pm Post subject: |
|
|
| Thanks for all the help. I'm going to look into it and see if the calendar function in that dll will suit my needs. |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Sun Jun 15, 2003 9:26 pm Post subject: |
|
|
You can also use edit masking in the VDSOBJ02.DLL  _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
|