urgent : how to readln DATE ??? 
Author Message
 urgent : how to readln DATE ???

hi...

how to readln the date from user???
is it first declare the format in type section like

type
        datetype = rec
                dd : integer;
                mm: integer;
                yyyy: integer;
                end;

var
        date : datetype;

then read(date.dd, date.mm, date.yyyy);
or ???
how we can readln the date in 151199 then format it to 15/11/1999 ???

thanks
dennis



Fri, 03 May 2002 03:00:00 GMT  
 urgent : how to readln DATE ???

Quote:
> how to readln the date from user???
> is it first declare the format in type section like
> type
>    datetype = rec
>            dd : integer;
>            mm: integer;
>            yyyy: integer;
>            end;
> var        date : datetype;

> then read(date.dd, date.mm, date.yyyy);
> or ???
> how we can readln the date in 151199 then format it to 15/11/1999 ???

   This is s style and interface issue, and there are no absolutes
excepts as defined by the application.  The sophistication of the
interface and the users tend to constrain such things, and how
knowledgeable (or malicious) your users might me should be a strong
consideration.
   First, I suggest you model your prompt in such a way as to tell users
how you expect the data to be entered:

  write ('Enter Date as mm/dd/yyyy ')

so they know the format and range of information desired by the
application.  Then, I think the program should read whatever's keyed in
as a string variable and parse the specific fields.  Parsing from string
data provides protection against errors and/or deliberate attempts to
crash the application, and it allows the program to stay in an "entry
loop" until acceptable data is presented.
   I would also allow/accommodate in such a case that the user omits the
"/" separators (enters the information as "mmddyyyy"), and even perhaps a
shortened "year" value (if you have a way to assure century rollover and
distinction, that is).  I would also allow a single-digit value for the
"mm" portion, since it's easy enough to determine a valid month value (1-
12) versus the day and year data.  These things are your choice, of
course, and could depend on data entry performance/volume issues, too.
   Then, the program can work with the separate fields and present them
to the user with whatever formatting is desired.



Fri, 03 May 2002 03:00:00 GMT  
 urgent : how to readln DATE ???

Quote:

> > how to readln the date from user???
> > is it first declare the format in type section like
> > type
> >       datetype = rec
> >               dd : integer;
> >               mm: integer;
> >               yyyy: integer;
> >               end;
> > var   date : datetype;

> > then read(date.dd, date.mm, date.yyyy);
> > or ???
> > how we can readln the date in 151199 then format it to 15/11/1999 ???

>    This is s style and interface issue, and there are no absolutes
> excepts as defined by the application.  The sophistication of the
> interface and the users tend to constrain such things, and how
> knowledgeable (or malicious) your users might me should be a strong
> consideration.
>    First, I suggest you model your prompt in such a way as to tell users
> how you expect the data to be entered:

>   write ('Enter Date as mm/dd/yyyy ')

> so they know the format and range of information desired by the
> application.  Then, I think the program should read whatever's keyed in
> as a string variable and parse the specific fields.  Parsing from string
> data provides protection against errors and/or deliberate attempts to
> crash the application, and it allows the program to stay in an "entry
> loop" until acceptable data is presented.
>    I would also allow/accommodate in such a case that the user omits the
> "/" separators (enters the information as "mmddyyyy"), and even perhaps a
> shortened "year" value (if you have a way to assure century rollover and
> distinction, that is).  I would also allow a single-digit value for the
> "mm" portion, since it's easy enough to determine a valid month value (1-
> 12) versus the day and year data.  These things are your choice, of
> course, and could depend on data entry performance/volume issues, too.
>    Then, the program can work with the separate fields and present them
> to the user with whatever formatting is desired.

     I agree with Mike.  Note that if you attempt to read, for example,
"111999" (for 11/19/99) as an integer, you'll get a pretty big number that
you'll have to (with arithmetic!)
pull apart into month, day, and year.  If you read it in as characters, it
comes already "pulled apart", and you only have to "put it back together".

     Note that, if you are guaranteed that the user will enter with the
format 11/19/99, you CAN read in the month, day, and year as integers, using
a character read to skip over the
slash.  That's because Pascal will parse numbers until it sees a "non-number"
character.  So
one COULD read this type of input with

    VAR month, day, year : integer;
      slash : char;

   readln (month, slash, day, slash, year);

Note that one or two-digit months would parse correctly.  Two digit years
would be detected as being <100 (and you could use whatever algorithm you
chose to add on the proper century).  However, should the user omit the
separator, and put, say, 111999, this
readln statement would give "unexpected results".

Bob Schor
Pascal Enthusiast



Fri, 03 May 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. URGENT ** Problem with Iteration ** URGENT

2. readln in pixel graphics

3. readln inside a procedure

4. READLN help???????????

5. Differences between READ and READLN

6. help needed with readln

7. read/readln procedures

8. strange readln problem

9. Differences between READ and READLN

10. Readln

11. Limitations of readln?!?!?

12. readln too small..

 

 
Powered by phpBB® Forum Software