Carl,
Thanks. I see how this works. I guess the date? function isn't really
processing the date and is just reporting back validity for the datatype
query. You are correct about the date I am retrieving - it is coming in as
a string from an ASK statement to start with and I could use try as
indicated in your code below.
This is my first 'real' and 'original' project with Rebol and my first real
programming project outside of course-material and manipulating other
Rebolers code for my own purposes. I'm trying to create a 'Scheduling'
program/database for a 'rotating-shift oriented' workplace. I'm starting
out text based and will add a /View GUI later. I've had enough of a
challenge just getting the logic working properly without worrying about the
GUI problems that will arise.
I ran into this particular problem while trying to error-check data entry
for a small function. My code is quickly getting large as I'm struggling to
find adequate methods of code reuse. An example would be how to pass a
parameter to a function that is later used in a data element path ie.
record/:var-item-no. I would use a foreach statement to loop through each
'word in a series and each word would actually reference data elements from
the data series. This would prompt the user for the specific element and
then do the error checking, here's some sample code where code-reuse would
be helpful.....
until [sched-block/cell: ask "Enter Cell Prime: " find employees
sched-block/cell]
until [sched-block/p8am: ask "Enter Prostar 8am Prime: " find employees
sched-block/p8am]
until [sched-block/p9am: ask "Enter Prostar 9am Prime: " find employees
sched-block/p9am]
The 'until is doing the continuous error checking based on the result of the
'find statements success
Brock
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of
Carl Read
Sent: Saturday, October 13, 2001 4:03 AM
To: [EMAIL PROTECTED]
Subject: [REBOL] Re: Question about date? function
On 13-Oct-01, Brock & Janet wrote:
> Should the date? function return false if an invalid date is
> entered?
> For example, when entering (YYYY-MM-DD);
>>> date? 2001-12-25
> == true
> So you would think that a False would be returned if a date was
> incorrect, however, unexpectedly;
>>> date? 2001-13-25
> ** Syntax Error: Invalid date -- 2001-13-25
> ** Near: (line 1) date? 2001-13-25
> Since date? doesn't return a false but a Syntax Error. When I try
> the following I would expect it to gracefully allow me to enter an
> invalid date and allow me to write code around it to correct it.
>>> if error? try [ date? 2001-13-25] [print "An invalid date was
>>> entered"]
> ** Syntax Error: Invalid date -- 2001-13-25
> ** Near: (line 1) error? try [ date? 2001-13-25]
> Any thoughts?
I'd think the error occurs because it's an invalid datatype, same as
entering...
>> 100s
** Syntax Error: Invalid integer -- 100s
is invalid. When a script's running though, any dates entered would
probably start out as a string, so just check for an error when
converting it to a date...
>> if error? try [to-date "2001-13-25"][print "Date error!"]
Date error!
--
Carl Read
--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without the quotes.
--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without the quotes.