home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / io / io_22 / io22demo.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1987-05-24  |  15.4 KB  |  470 lines

  1. program IO22DEMO ;
  2.   { This program demonstrates Turbo Pascal console I/O routines for an
  3.     elegant user interface.
  4.       Original version          --  4/18/86.
  5.       Added day of week display -- 10/ 9/86.
  6.       Version 2.2 enhancements  --  5/24/87.
  7.  
  8.     PUBLIC DOMAIN, NO COPYRIGHT
  9.       William Meacham
  10.       1004 Elm Street
  11.       Austin, Tx  78703
  12.  
  13.     NOTES FOR CP/M:
  14.       *  Comment out IBM version of proc KEYIN in file IO22.INC
  15.          and un-comment CP/M version of proc KEYIN.
  16.       *  Change text of instruction screen below.  As written, it is for IBM.
  17.          For CP/M, DEL is destructive backspace and Backspace is
  18.          non-destructive character-left.
  19.       *  Comment out call to Lowvideo at beginning of main routine, below.
  20.       *  Compile to COM file with End address of $8000. }
  21.  
  22. {$c-,v-}
  23. {$i io22.inc }                      { Console I/O (user interface) routines }
  24. {$i date22.inc }                    { Date routines }
  25.  
  26. var
  27.     choice           : integer ;    { to get menu choice }
  28.     quitnow          : boolean ;    { to get user Y/N input }
  29.  
  30. { ------------------------------------------------------------ }
  31.  
  32. procedure title_screen ;
  33.  
  34. label 99 ;
  35.  
  36. const
  37.     dly = 500 ;
  38.  
  39. var
  40.     ch : char ;
  41.     i  : integer ;
  42.  
  43.     begin
  44.         clrscr;
  45.         write_str ('------------------',31,6) ;
  46.         write_str ('                  ',31,7) ;
  47.         write_str ('   Demonstration  ',31,8) ;
  48.         write_str ('        of        ',31,9) ;
  49.         write_str ('   Turbo Pascal   ',31,10) ;
  50.         write_str ('  User Interface  ',31,11) ;
  51.         write_str ('                  ',31,12) ;
  52.         write_str ('------------------',31,13) ;
  53.         write_str ('    Reliance Software Services',23,18) ;
  54.         write_str ('1004 Elm Street, Austin, Tx  78703',23,19) ;
  55.         write_str ('   Public Domain - No Copyright',23,21) ;
  56.         write_str ('PRESS SPACE BAR TO CONTINUE',26,24) ;
  57.         fld := 0 ;
  58.         i := 0 ;
  59.         while i < maxint do
  60.           begin
  61.             if keypressed then
  62.               begin
  63.                 keyin(ch) ;
  64.                 if (ch = #$20) or (ch = #$1B) then
  65.                   begin
  66.                     i := maxint ;
  67.                     if ch = #$1B then
  68.                         fld := maxint ;
  69.                     goto 99
  70.                   end
  71.               end ;
  72.             if i mod 337 = 0 then
  73.               begin
  74.                 write_str ('*',31,6) ;
  75.                 gotoxy (54,24) ;
  76.                 delay (dly) ;
  77.                 write_str ('-',31,6) ;
  78.                 gotoxy (54,24)
  79.               end ;
  80.             if i mod 523 = 0 then
  81.               begin
  82.                 write_str ('*',45,8) ;
  83.                 gotoxy (54,24) ;
  84.                 delay (dly) ;
  85.                 write_str ('o',45,8) ;
  86.                 gotoxy (54,24)
  87.               end ;
  88.             if i mod 1024 = 0 then
  89.               begin
  90.                 write_str ('*',35,11) ;
  91.                 gotoxy (54,24) ;
  92.                 delay (dly) ;
  93.                 write_str ('e',35,11) ;
  94.                 gotoxy (54,24)
  95.               end ;
  96.             if i mod 1118 = 0 then
  97.               begin
  98.                 write_str ('*',48,13) ;
  99.                 gotoxy (54,24) ;
  100.                 delay (dly) ;
  101.                 write_str ('-',48,13) ;
  102.                 gotoxy (54,24)
  103.               end ;
  104.             i := succ(i) ;
  105.             if i = maxint then
  106.                 i := 0 ;
  107. 99:
  108.           end ; { while i < maxint }
  109.  
  110.         if fld = maxint then
  111.           begin
  112.             gotoxy (1,23) ;
  113.             halt
  114.           end
  115.     end ; { proc title_screen }
  116.  
  117. { ------------------------------------------------------------ }
  118.  
  119. procedure display_menu ;
  120. begin
  121.     clrscr ;
  122.     write_str('USER INTERFACE DEMONSTRATION',26,3) ;
  123.     write_str('MAIN MENU',36,4) ;
  124.     write_str('Please select:',26,6) ;
  125.     write_str('1    Display instructions',26,8) ;
  126.     write_str('2    Data entry and display demo for',26,10) ;
  127.     write_str('Strings, Integers, Reals and Booleans',31,11) ;
  128.     write_str('3    Data entry and display demo for Dates',26,13) ;
  129.     write_str('ESC  Exit the program',26,15) ;
  130.     write_str('==>',26,17)
  131. end ; { proc display_menu }
  132.  
  133. { ------------------------------------------------------------ }
  134.  
  135. procedure display_instructions ;
  136. begin
  137.     clrscr;
  138.     writeln('                                   Labelled     Arrow   Ctrl     Function') ;
  139.     writeln('     COMMAND                         key         key    key      key (IBM)') ;
  140.     writeln('     --------------------------    --------     -----   ----     ---------') ;
  141.     writeln('  *  DELETE character at cursor      Del                  G         F1') ;
  142.     writeln('  *  DELETE character to left      Backspace') ;
  143.     writeln('  *  DELETE entire entry                                  Y         F2') ;
  144.     writeln ;
  145.     writeln('  *  MOVE LEFT one character                    left      S         F5') ;
  146.     writeln('  *  MOVE RIGHT one character                   right     D         F6') ;
  147.     writeln ;
  148.     writeln('  *  MOVE FORWARD to next field     Enter       down      X         F4') ;
  149.     writeln('  *  MOVE BACK to previous field                 up       E         F3') ;
  150.     writeln ;
  151.     writeln('  *  PAGE FORWARD to next screen                PgDn      C         F8') ;
  152.     writeln('  *  PAGE BACK to previous screen               PgUp      R         F7') ;
  153.     writeln ;
  154.     writeln('  *  CANCEL data entry               Esc') ;
  155.     writeln ;
  156.     writeln('  *  TO ENTER DATA:   Type the data & press Enter or a field or page key.') ;
  157.     writeln('  *  TO ENTER YES/NO: Type "Y" or "N;" don''t press Enter.') ;
  158.     writeln('  *  TO ENTER A DATE: Type the month, 2 digits, the day, 2 digits,') ;
  159.     writeln('                      and the year, 2 or 4 digits, and press Enter.') ;
  160.     hard_pause ;
  161.     fld := 1 { reset FLD for calling proc }
  162. end ; { proc display_instructions }
  163.  
  164. { ------------------------------------------------------------ }
  165.  
  166. procedure io_demo ;
  167.   { demonstrate I/O of strings, integers, reals and booleans }
  168.  
  169. var
  170.     first, last, addr1, addr2, city,
  171.           state, zip : str_type ;   { for string demo }
  172.     i1, i2, i3, itot : integer ;    { for integer demo }
  173.     r1, r2, r3, rtot : real ;       { for real demo }
  174.     b1, b2, b3, b4   : boolean ;    { for boolean demo }
  175.  
  176. { ==================== }
  177.  
  178. procedure init_io_vars ;
  179.   { Initializes global variables }
  180.     begin
  181.         first := '' ;
  182.         last  := '' ;
  183.         addr1 := '' ;
  184.         addr2 := '' ;
  185.         city  := '' ;
  186.         state := '' ;
  187.         zip   := '' ;
  188.         i1 := 0 ;
  189.         i2 := 0 ;
  190.         i3 := 0 ;
  191.         itot := 0 ;
  192.         r1 := 0 ;
  193.         r2 := 0 ;
  194.         r3 := 0 ;
  195.         rtot := 0 ;
  196.         b1 := false ;
  197.         b2 := false ;
  198.         b3 := false ;
  199.         b4 := false
  200.     end ; { proc init_io_vars }
  201.  
  202. { ==================== }
  203.  
  204. procedure strings ;
  205.   { This procedure demonstrates reading and writing strings. }
  206.  
  207.     var
  208.         i  : integer ; { For loop control }
  209.         ok : boolean ; { Whether zip code is numeric }
  210.  
  211.     begin
  212.         clrscr ;
  213.         write ('SCREEN ', scrn, ' -- STRINGS') ;
  214.         write_str ('First name:',9,8) ;
  215.         write_str (first,21,8 ) ;
  216.         write_str ('Last name:',9,9) ;
  217.         write_str (last,21,9) ;
  218.         write_str ('Address 1:',9,10) ;
  219.         write_str (addr1,21,10) ;
  220.         write_str ('Address 2:',9,11) ;
  221.         write_str (addr2,21,11) ;
  222.         write_str ('City:',9,12) ;
  223.         write_str (city,21,12) ;
  224.         write_str ('State:',9,13) ;
  225.         write_str (state,21,13) ;
  226.         write_str ('Zip:',9,14) ;
  227.         write_str (zip,21,14) ;
  228.         fld := 1 ;
  229.         repeat
  230.                 case fld of
  231.                   1: read_str (first, 15, 21, 8) ;
  232.                   2: read_str (last, 10, 21, 9) ;
  233.                   3: read_str (addr1, 15, 21, 10) ;
  234.                   4: read_str (addr2, 15, 21, 11) ;
  235.                   5: read_str (city, 15, 21, 12) ;
  236.                   6: read_str (state, 2, 21, 13) ;
  237.                   7: begin
  238.                        repeat
  239.                            read_str (zip, 5, 21, 14) ;
  240.                            ok := true ;
  241.                            if not (zip = '') then
  242.                                begin
  243.                                    if length (zip) < 5 then
  244.                                            ok := false
  245.                                    else
  246.                                            for i:= 1 to 5 do
  247.                                                if (zip[i] <'0')
  248.                                                or (zip[i] >'9') then
  249.                                                    ok := false
  250.                                end ;
  251.                            if not ok then
  252.                              begin
  253.                                show_msg ('MUST BE NUMERIC OR NOT ENTERED') ;
  254.                                zip := '' ;
  255.                                fld := 7
  256.                              end
  257.                        until ok ;
  258.                      end ; { 7: }
  259.                 end ; { case }
  260.         until (fld < 1) or (fld > 7) ;
  261.         do_scrn_ctl
  262.     end ; { proc strings }
  263.  
  264. { ==================== }
  265.  
  266. procedure integers ;
  267.   { This procedure demonstrates reading & writing integers. }
  268.  
  269.     procedure sum_int ;
  270.         begin
  271.             itot := i1 + i2 + i3 ;
  272.             write_int (itot, 5, 13, 12)
  273.         end ;
  274.  
  275.     begin { integers }
  276.         clrscr ;
  277.         write ('SCREEN ', scrn, ' -- INTEGERS') ;
  278.         write_str ('==>', 9, 8) ;
  279.         write_int (i1,4,14,8) ;
  280.         write_str ('==>', 9, 9) ;
  281.         write_int (i2,4,14,9) ;
  282.         write_str ('==>', 9, 10) ;
  283.         write_int (i3,4,14,10) ;
  284.         write_str ('TOTAL', 7, 12) ;
  285.         write_int (itot,5,13,12) ;
  286.         fld := 1 ;
  287.         repeat
  288.                 case fld of
  289.                   1: begin
  290.                        read_int (i1, 4, 14, 8) ;
  291.                        sum_int ;
  292.                      end ;
  293.                   2: begin
  294.                        read_int (i2, 4, 14, 9) ;
  295.                        sum_int ;
  296.                      end ;
  297.                   3: begin
  298.                        read_int (i3, 4, 14, 10) ;
  299.                        sum_int ;
  300.                      end ;
  301.                   4: pause ;
  302.                 end ; { case }
  303.         until (fld < 1) or (fld > 4 ) ;
  304.         do_scrn_ctl
  305.     end ; { proc integers }
  306.  
  307. { ==================== }
  308.  
  309. procedure reals ;
  310.   { This procedure demonstrates reading & writing reals. }
  311.  
  312.     const
  313.         tot  = 11 ;
  314.         frac = 3  ;
  315.  
  316.     procedure sum_real ;
  317.         begin
  318.             rtot := r1 + r2 + r3 ;
  319.             write_real (rtot, tot+1, frac, 13, 12)
  320.         end ;
  321.  
  322.     begin { proc reals }
  323.         clrscr ;
  324.         write ('SCREEN ', scrn, ' -- REALS') ;
  325.         write_str ('==>', 9, 8) ;
  326.         write_real (r1,tot,frac,14,8) ;
  327.         write_str ('==>', 9, 9) ;
  328.         write_real (r2,tot,frac,14,9) ;
  329.         write_str ('==>', 9, 10) ;
  330.         write_real (r3,tot,frac,14,10) ;
  331.         write_str ('TOTAL', 7, 12) ;
  332.         write_real (rtot,12,3,13,12) ;
  333.         fld := 1 ;
  334.         repeat
  335.                 case fld of
  336.                   1: begin
  337.                        read_real (r1, tot,frac, 14, 8) ;
  338.                        sum_real ;
  339.                      end ;
  340.                   2: begin
  341.                        read_real (r2, tot,frac, 14, 9) ;
  342.                        sum_real ;
  343.                      end ;
  344.                   3: begin
  345.                        read_real (r3, tot,frac, 14, 10) ;
  346.                        sum_real ;
  347.                      end ;
  348.                   4: pause ;
  349.                 end ; { CASE }
  350.         until (fld < 1) or (fld > 4 ) ;
  351.         do_scrn_ctl
  352.     end ; { proc reals }
  353.  
  354. { ==================== }
  355.  
  356. procedure booleans ;
  357.   { This procedure demonstrates reading & writing booleans }
  358.     begin
  359.         clrscr;
  360.         write ('SCREEN ', scrn, ' -- BOOLEANS') ;
  361.         write_str ('TYPE OF CO-BORROWER.  Type "Y" for all that apply.',3,8) ;
  362.         write_str ('"No" will be assumed if you just press <RETURN>.',3,9) ;
  363.         write_str ('1 - Another person will be jointly obligated with borrower',5,10) ;
  364.         write_str ('2 - Borrower is relying on income of another person',5,11) ;
  365.         write_str ('3 - Married, living in a community property state',5,12) ;
  366.         write_bool (b1, 71, 10) ;
  367.         write_bool (b2, 71, 11) ;
  368.         write_bool (b3, 71, 12) ;
  369.         write_str ('Epimenides the Cretan says, "All Cretans are liars!"  Is he lying?',3,14) ;
  370.         write_bool (b4, 71, 14) ;
  371.         fld := 1 ;
  372.         repeat
  373.             case fld of
  374.               1: read_bool (b1, 71, 10) ;
  375.               2: read_bool (b2, 71, 11) ;
  376.               3: read_bool (b3, 71, 12) ;
  377.               4: read_bool (b4, 71, 14) ;
  378.               5: pause ;
  379.             end ; { case }
  380.         until (fld <1) or (fld > 5) ;
  381.         do_scrn_ctl
  382.     end ; { booleans }
  383.  
  384. { ==================== }
  385.  
  386. procedure final_screen ;
  387.   { The final screen -- demonstrates proc Read_YN }
  388.     var
  389.         more : boolean ;
  390.     begin
  391.         clrscr ;
  392.         write_str ('End of demonstration.',20, 10) ;
  393.         write_str ('Do it again?',20, 12) ;
  394.         read_yn (more, 34, 12) ;
  395.         if more then
  396.             scrn := 1
  397.         else
  398.             scrn := succ(scrn)
  399.     end ; { proc final_screen }
  400.  
  401. { ==================== }
  402.  
  403. begin { ----- proc io_demo ----- }
  404.     scrn := 1 ;
  405.     init_io_vars ;
  406.     repeat
  407.         case scrn of
  408.           1 : strings  ;
  409.           2 : integers ;
  410.           3 : reals ;
  411.           4 : booleans ;
  412.           5 : final_screen
  413.         end ; { case }
  414.         if scrn < 1 then
  415.               scrn := 1           { no going backward from first screen }
  416.         else if scrn > 6 then
  417.               scrn := 5           { trap ESC }
  418.     until scrn > 5 ;
  419.     fld := 1 ;                    { reset FLD for calling proc }
  420. end ; { proc io_demo }
  421.  
  422. { ------------------------------------------------------------ }
  423.  
  424. {$i datedemo.inc -- procedure date_demo }
  425.  
  426. { ------------------------------------------------------------ }
  427.  
  428. begin { --- program IO22DEMO --- }
  429.     lowvideo ;
  430.     title_screen ;
  431.     repeat
  432.         display_menu ;
  433.         repeat
  434.             fld := 1 ;
  435.             choice := 0 ;
  436.             read_int (choice,1, 31,17) ;
  437.             if fld < 1 then choice := 0 ;
  438.             if fld = maxint then
  439.               begin
  440.                 write_str (' ',31,17) ;
  441.                 write_str ('QUIT NOW? (Y/N)',26,19) ;
  442.                 read_yn (quitnow,42,19) ;
  443.                 if not quitnow then
  444.                   begin
  445.                     fld := 1 ;
  446.                     choice := 0 ;
  447.                     clrline (26,19)
  448.                   end
  449.               end ;
  450.         until (choice in [1 .. 3]) or (fld = maxint) ;
  451.         if not (fld = maxint) then
  452.             case choice of
  453.               1: display_instructions ;
  454.               2: io_demo ;
  455.               3: date_demo ;
  456.             else
  457.                  beep
  458.             end  { case }
  459.     until fld = maxint ;
  460.     clrscr ;
  461.     write_str ('Thank you for trying the Reliance User Interface Demonstration',12,5) ;
  462.     write_str ('Program.  Please send me your comments and suggestions.',12,6) ;
  463.     write_str ('Bill Meacham',30,10) ;
  464.     write_str ('Reliance Software Services',24,11) ;
  465.     write_str ('1004 Elm Street',29,12) ;
  466.     write_str ('Austin, Tx  78703',28,13) ;
  467.     writeln ; writeln
  468. end.
  469.  
  470.