home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / TPPROC19.ZIP / CHECK.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-09-08  |  6.0 KB  |  230 lines

  1.  
  2. {
  3. a procedure to check to make sure the date was entered (by assuming
  4. that 1980 is invalid) and to request entry of date and offer the
  5. option of entering time. v. 2.0  (c) copyright 1985 -- J. Levine
  6. Public Domain -- a learning exercise -- last update 8/29
  7.  
  8.  
  9. -----------------------------------------------------------}
  10. TYPE
  11. REGPACK = record          {establish record for registers}
  12.         case integer of
  13.         1: (Ax,Bx,Cx,Dx,Bp,Di,Si,Ds,Es,Flags : integer);
  14.         2: (Al,Ah,Bl,Bh,Cl,Ch,Dl,Dh : byte);
  15.         END;
  16.  
  17. VAR
  18. rg : regpack;              {variable to be used within procedures}
  19.  
  20. {------------------------------------------------------------------------}
  21. function GetChar : char;
  22. VAR
  23. Rg : REGPACK;           { register structure }
  24.  
  25.    BEGIN
  26.    Rg.Ah := $01;           { set AH and perform DOS interrupt }
  27.    Intr( $21, Rg );
  28.    GetChar := char(Rg.Al);
  29.    END;
  30.  
  31. {-------------------------------------------------------------------------}
  32.  
  33. { Fill passed variables with current date from DOS }
  34.  
  35. procedure GetDate ( VAR Yr : integer );
  36.  
  37.  
  38. BEGIN
  39. With rg DO            {using the registers}
  40.      BEGIN
  41.      Ah := $2A;      { set AH and perform DOS interrupt }
  42.      Intr( $21, Rg );
  43.      Yr := Cx;       { set passed variables to register values }
  44.      END;
  45. END;
  46. {------------------------------------------------------------------------}
  47. procedure requesttime;
  48.  
  49. TYPE
  50. string1 = string[1];  {set up the string types}
  51. string2 = string[2];
  52. string5 = string[5];
  53.  
  54. VAR
  55. hour, minutes, code : integer;          {for use with val}
  56. time: string5;
  57. h,m,x : string2;
  58. ok, again : boolean;
  59.  
  60.  
  61. BEGIN
  62. ok := true;
  63. again := true;
  64.       WHILE again = true
  65.       DO
  66.             BEGIN
  67.             writeln;
  68.             writeln('Please enter the time (HH:MM)  ');
  69.             writeln;
  70.             readln(time);
  71.             h := copy(time,1,2);  {take first two letters}
  72.             m := copy(time,4,2);  {then next two letters}
  73.             x := copy(time,3,1);  {then get the colon}
  74.             val(h,hour,code)     ;  {return the value of the hours}
  75.             val(m,minutes,code)  ;  {return the value of the minutes}
  76.                IF code >0
  77.                THEN ok := false;  {make sure its an integer}
  78.                IF x <> ':'
  79.                THEN ok := false; {check for colon}
  80.             again := false;
  81.  
  82.             with rg DO
  83.                  BEGIN
  84.                  Ah := $2d;           { set AH and perform DOS interrupt }
  85.                  Ch := Hour;    { set passed variables to register values }
  86.                  Cl := Minutes;
  87.                  Intr( $21, Rg );
  88.  
  89.                          IF al <> 0
  90.                          THEN ok := false;
  91.                          WHILE not ok
  92.                          DO
  93.                            BEGIN
  94.                            clrscr;
  95.                            writeln('Ooops! -- not in proper format');
  96.                            writeln('please try again');
  97.                            ok := true;
  98.                            again := true
  99.                            END;
  100.                   END;
  101.  
  102.         END; {for with rg do}
  103.  
  104.    END;
  105.  
  106.  
  107.  
  108. {----------------------------------}
  109. procedure putdate;
  110.  
  111.  
  112.  
  113.  
  114. TYPE
  115. string1 = string[1];
  116. string4 = string[4];  {set up the string types}
  117. string2 = string[2];
  118. string8 = string[8];
  119.  
  120.  
  121. VAR
  122. m,d : string2;          {for use with val}
  123. y : string2;
  124. year: string8;
  125. mon,dat,yr,code : integer;
  126. ok, again : boolean;
  127. dasha : string1;
  128. dashb : string1;
  129.  
  130.  
  131. BEGIN
  132. ok := true;         { initialize variables }
  133. again := true;
  134.  
  135. WHILE again
  136. DO
  137.   BEGIN
  138.   writeln;
  139.   writeln('Please enter the date (MM-DD-YY)  ');
  140.   writeln;
  141.   readln(year);
  142.   IF length(year) < 1
  143.   THEN
  144.   ok := false;
  145.  
  146.   code := 0;
  147.   m := copy(year,1,2);    {take first two letters}
  148.   d := copy(year,4,2);    {then next two letters}
  149.   y := copy(year,7,2);    {then get the year}
  150.   dasha := copy(year,3,1);
  151.   dashb := copy(year,6,1);
  152.   val(m,mon,code)     ;   {return the value of the month}
  153.   val(d,dat,code)  ;      {return the value of the date}
  154.   val(y,yr,code) ;        {returns the value of the year}
  155.  
  156.  
  157.       ok := (code = 0) and ((dasha = '-') or (dasha = '/')) and
  158.       ((dashb = '-') or (dashb = '/')) and (yr in [81..99]);
  159.  
  160.       yr := yr + 1900;
  161.  
  162.       WITH rg
  163.       DO
  164.         BEGIN
  165.         Ah := $2b;    { set AH and perform DOS interrupt }
  166.         Cx := Yr;    {set passed variables to register values }
  167.         Dh := Mon;
  168.         Dl := Dat;
  169.         Intr( $21, Rg );
  170.         END; {end dos call}
  171.  
  172.       again :=false;
  173.  
  174.         WHILE not ok
  175.         DO
  176.           BEGIN
  177.           clrscr;
  178.           writeln('Ooops! -- not in proper format');
  179.           writeln('please try again');
  180.           writeln;
  181.           again := true;
  182.           ok := true
  183.           END; {end while not ok}
  184.         END; {end while}
  185. END; {end procedure}
  186. {------------------------------------------------------------------------}
  187. { main body of program }
  188.  
  189. VAR                                    {set up the variables}
  190. Year : integer;
  191. ans : char;
  192.  
  193.  
  194.       BEGIN  {body of program}
  195.       Getdate ( Year );    {get the year}
  196.       IF year = 1980
  197.       THEN     {check to see IF year set}
  198.                BEGIN
  199.  
  200.                clrscr;
  201.  
  202.                writeln; {drop down from top}
  203.                writeln;
  204.                writeln;
  205.                writeln('You forgot to set the date!');
  206.                writeln;
  207.                writeln('Let''s do it now... ');
  208.  
  209.                putdate;
  210.                writeln;
  211.  
  212.                 REPEAT
  213.                 write('Do you want to enter the time? <Y/N> ');
  214.                 ans := upcase(getchar);
  215.                 UNTIL
  216.                 ans in ['Y','N'];
  217.  
  218.                 IF  ans = 'Y'
  219.                 THEN
  220.                     BEGIN
  221.                     clrscr;
  222.                     requesttime;
  223.                     END; {end if ans = Y}
  224.          END;   {end if year = 1980}
  225.  
  226. END.  {end program}
  227.  
  228.  
  229.  
  230.