Pascal Virgin Requires Experience! On Dates! ?? 
Author Message
 Pascal Virgin Requires Experience! On Dates! ??

Re: Your posting below:

========
Newsgroups: comp.lang.Pascal.borland
Subject: ?? Pascal {*filter*} Requires Experience! On Dates! ??

Date: Tue, 07 May 96 10:24:20 GMT

Hi All

I have a problem!  I am writing a menu system for a sports database,
one of the Menu selections has an option to
add a member.  Once this option is selected the program goes to an
input form for Name, Address etc.  I am having
trouble with two fields called Date-Of-Joining and Date-Of-Birth.  At
present there is no error checking on the
form and all the fields are string.  The dates are two fields within a
record which are stored in an array.

I want to have an input form on the dates so the day-month-year (I am
in the UK, that's the way round we do our
dates) separators are on screen all ready when you go into the add
member screen. I am thinking of using
VAL to turn the String Values for the dates to numeric format and
using that to validate the dates, to make sure
numbers are entered.  I have a procedure to check for valid dates to.
My problem is with reading in the dates.
When I enter the day I want the cursor to skip past the first
separator and go to the first position in the month
field.  I know I can do this with GOTOXY but how do I get the day
month read into a variable and move the cursor on
?  I have been used to using READLN to read in variables and I don't
know how to read the day into a variable
and to move the cursor with out getting the user to press ENTER.  Has
anyone got any ideas ??

Do I need to use READ instead of READLN ??  I heard that you can only
use two read's on One line as READ read's from the
current Line and doesn's do a carriage return and goto the next line
like READLN.  I have also looked at ReadKey
and Keypress but I am not sure if either meet my needs.  So can anyone
help ???  I guess having separate variables
for day-month-year for both of the dates would be more appropriate.  I
know that GETdate could help me with
Date-Of-Joining, but that still leaves me with Date-Of-Birth, and
anyway Date-Of-Joining might not be the same as
the day the member is entered so I want to find a better way!

Thanks in advance!!
Lee
------------------------ end of query

Lee,

You can add your check for valid dates to the following and modify it
to suit your fancy--but it does jump the delimiters and screens
against non-numeric entries.

Regards,
Clif

Program Da{*filter*}try;

In this program a date is entered as dd/mm/yy but the delimiting /'s
are already in place. Each digit is keyed in as a numeric character
one at a time with ReadKey and stored in the proper position in a
two char string. ReadKey does not echo the key character so a Write
is added for that. After each pair of digit chars is keyed in, VAL
is used to convert the two char string buff to an integer. If only
numeric characters are present AND the ranges for day, 1..31, and
month, 1..12, are met--each two digit number is stored in an array
variable. If dd is proper, the cursor jumps over the / to the mm
location (no enter is pressed). If the month is proper, the cursor
jumps to the yy location. If any of the three entries is wrong, (1)
a beep is heard, (2) the cursor returns to the beginning of that two
digit entry and (3) the wrong two digits are erased. The program may
be exited by pressing escape at any time. As written no enter is
pressed to enter any of the date components.  }

Uses CRT;

CONST
Delimit = '   /  /  ';
Esc = Chr(27);
Beep = Chr(7);

VAR
Dt:Array [1..3] of Integer;
buff:String[2];
n, p, x, y, code:Integer;
proper:Boolean;

BEGIN
     ClrScr;
     Writeln('***** Press <Esc> at any time to quit *****');
     Repeat
           Writeln;  Write('Enter date as dd/mm/yy: ');
           x := WhereX;
           y := WhereY;
           Write(Delimit);
           For n := 1 to 3 do
           Begin
                x := x + 1;
                Repeat
                      buff := '  ';
                      GotoXY(x, y);
                      Write(buff);  (* in case if entry error *)
                      GotoXY(x, y);

                      For p := 1 to 2 do
                      Begin
                           buff[p] := ReadKey;
                           If buff[p] <> Esc then Write(buff[p])
                           Else EXIT;
                      End;

                      VAL(buff, Dt[n], code);
                      proper := code = 0;
                      If proper then
                      Begin
                           Case n of
                             1: proper := Dt[1] in [1..31];
                             2: proper := Dt[2] in [1..12];
                           End;
                      End;
                      If not proper then Write(Beep);
                Until proper;
                x := WhereX;
           End;
           Writeln;
{          Readln;     optional if you wish to press enter  }
           Writeln ('Date integers in order of entry: ');
           For n := 1 to 3 do Writeln(Dt[n]);
     Until buff[p] = Esc;
END.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. ?? Pascal Virgin Requires Experience! On Dates! ??

2. ?? Pascal Virgin Requires

3. Have any others experienced this in pascal?

4. Have any others experienced this in pascal?

5. Have any others experienced this Pascal Problem?

6. EU Borland Pascal programmer required.(EU only apply)

7. Pascal Required

8. Pascal Required

9. Turbo Pascal 7 Help Required

10. Help required with Record Swap in Pascal - Test3.pas (0/1)

11. pascal compiler help required.....

12. Help required on pascal programming

 

 
Powered by phpBB® Forum Software