home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / io / io_22 / io22demo.doc < prev    next >
Encoding:
Text File  |  1987-05-24  |  11.0 KB  |  289 lines

  1. DOCUMENTATION FOR IO22DEMO.PAS/COM -- 5/24/87
  2.  
  3. Bill Meacham
  4. 1004 Elm Street
  5. Austin, Tx  78703
  6.  
  7. PUBLIC DOMAIN -- NO COPYRIGHT
  8.  
  9. This program demonstrates a sophisticated method of controlling
  10. console data entry in Turbo Pascal.  It allows you precise
  11. control over where data entry occurs on the screen and makes your
  12. programs crash-proof from user input.  All the I/O (input/output)
  13. routines except for dates are in the Include file IO22.INC.
  14.  
  15. It also demonstrates a number of ways to manipulate and perform
  16. calculations with dates.  All the date routines are in the
  17. Include file DATE22.INC.  If you use this file, you must include
  18. IO22.INC first.
  19.  
  20. Put the compiler toggles {$C-,V-} at the top of your program,
  21. before the Include files.  $C- disables checking for control-C
  22. and makes the program run a bit faster.  $V- allows you to use
  23. strings of varying lengths.
  24.  
  25. The rest of this document describes the two Include files.
  26.  
  27.  
  28. DOCUMENTATION FOR IO22.INC --------------------------------------------
  29.  
  30. The functions and procedures in this Include module allow you to
  31. control console I/O with great precision.  You can read and write
  32. strings, integers, reals and booleans at any place on the screen
  33. and prevent the user from entering garbage.  User input cannot
  34. crash your program!  You can easily control cursor movement
  35. through data entry forms displayed on the screen, not only from
  36. field to field but from screen to screen.
  37.  
  38. The data input procedures, READ_STR, READ_INT, etc., have an
  39. intentional side-effect on the global variable FLD, which
  40. controls which field the cursor goes to.  Study the code in
  41. procedures STRINGS, INTEGERS, REALS and BOOLEANS in the
  42. demonstration program to see how a case statement within a
  43. repeat-until loop uses this variable.  Study the code in
  44. procedure IO_DEMO in the demonstration program to see how a
  45. similar case statement within a repeat-until loop uses the global
  46. variable SCRN to control which screen is displayed.
  47.  
  48. The rest of this section describes the global types, variables,
  49. procedures and functions that you can call from your program. 
  50. (There are a few more that are used by these procedures and
  51. functions, but are not intended to be called by themselves.)
  52.  
  53.  
  54. GLOBAL TYPES AND VARS
  55.  
  56. type
  57.     STR_TYPE = string[80] ;
  58.  
  59. var
  60.     FLD, SCRN   : integer ; { For field & screen cursor control. }
  61.  
  62.  
  63. PROCEDURES AND FUNCTIONS
  64.  
  65. procedure BEEP ;
  66.     Sounds the console bell.
  67.  
  68. function BUILD_STR (ch : chara ; n : integer) ;
  69.     Returns a string of length n of the character ch.
  70.  
  71. function CHOPCH (instr:str_type ; inchar:char) : str_type ;
  72.     Chops trailing instances of the character from the string.
  73.  
  74. procedure CLREOL ;
  75.     Built-in proc in Turbo to clear screen to end of line.
  76.  
  77. procedure CLRLINE (col,row : integer) ;
  78.     Clears screen to end of line starting at column and row specified.
  79.  
  80. procedure CLRSCR ;
  81.     Built-in procedure in Turbo to clear screen and place cursor at
  82.     upper left.
  83.  
  84. Function DEFINED (bool : boolean) : boolean ;
  85.     Tests whether boolean is defined.  "Defined" = True or False.
  86.     "Not defined" = neither True nor False; i.e user has not yet
  87.     answered a Yes/No question.  See also procedure Set_Bool.
  88.  
  89. procedure DO_SCRN_CTL ;
  90.     Checks value of FLD and adjusts value of SCRN accordingly.  Upon
  91.     exit SCRN is either one less than it used to be, one more, or
  92.     maxint.  If it is maxint you should exit from the series of screens.
  93.  
  94. function EQUAL (r1,r2 : real) : boolean ;
  95.     Tests functional equality of two real numbers (floating point, not
  96.     BCD).  Returns true if r1 equals r2 to a tolerance of 1/100,000.
  97.  
  98. procedure GOTOXY (col,row:integer) ;
  99.     Built-in procedure in Turbo to place cursor on screen at column
  100.     (horizontal) and row (vertical) position specified.  Upper left is
  101.     (1,1) not (0,0).
  102.  
  103. function GREATER (r1,r2 : real) : boolean ;
  104.     Tests functional inequality of two real numbers (floating point, not
  105.     BCD).  Returns True of r1 is greater than r2 to a tolerance of
  106.     1/100,000.
  107.  
  108. procedure HARD_PAUSE ;
  109.     Displays message on line 24, "PRESS SPACE BAR TO CONTINUE OR UP-ARROW
  110.     TO GO BACK."  Cursor can go forward only if user presses space bar. 
  111.     Cursor movement back and ESC key are enabled as well.
  112.  
  113. procedure KEYIN (var ch:char) ;
  114.     Accepts one character from the keyboard without echoing it back. 
  115.     Translates certain control characters and function keys to cursor
  116.     control keys recognized by the read_xxx procedures.
  117.  
  118. function PAD (st : str_type ; ch : char ; i : integer) : str_type ;
  119.     Pads string with ch to length of i.
  120.  
  121. procedure PAUSE ;
  122.     Displays message on line 24, "PRESS SPACE BAR TO CONTINUE."  Cursor
  123.     goes forward only if user presses space bar.  Cursor movement back
  124.     is disabled, but ESC is recognized.
  125.  
  126. function PURGECH (instr : str_type ; inchar : char) : str_type ;
  127.     Purges all instances of the character from the string.
  128.  
  129. procedure READ_BOOL (var bool:boolean; col,row:integer) ;
  130.     Displays boolean at column and row specified, inputs "Y"
  131.     or "N" to set new value of boolean, prints "YES" or "NO."
  132.       Note -- use this when the screen control may return to the
  133.     question.  Affects global FLD.
  134.  
  135. procedure READ_INT (var int:integer ; maxlen, col, row:integer) ;
  136.     Reads an integer from the keyboard, rejects invalid data.  COL and
  137.     ROW tell where to begin the data input field, and MAXLEN is the
  138.     maximum length of the character representation of the integer,
  139.  
  140. procedure READ_REAL (var r:real ; maxlen,frac,col,row:integer) ;
  141.     Reads a real number from the keyboard, rejects invalid data.  COL
  142.     and ROW tell where to begin the data input field; MAXLEN is the
  143.     maximum length of the string representation of the real number,
  144.     including sign and decimal point; FRAC is the fractional part, the
  145.     number of digits to right of the decimal point.  Designed to work
  146.     with floating point (not BCD) reals, but could work with BCDs as
  147.     well.  Note -- In Turbo the maximum number of significant digits in
  148.     a floating point real is 11.  It is the programmer's responsibility
  149.     to limit input and computed output to 11 significant digits. 
  150.  
  151. procedure READ_STR (var st:str_type ; maxlen, col, row:integer) ;
  152.     Reads a string from the keyboard, rejects invalid data.  COL and ROW
  153.     tell where to begin the data input field, and MAXLEN is the maximum
  154.     length of the string.
  155.  
  156. procedure READ_YN (var bool:boolean; col,row:integer) ;
  157.     Inputs "Y" OR "N" to boolean at column and row specified,
  158.     prints "YES" or "NO."
  159.       Note -- use this when the screen control will not return
  160.     to the question.  Does not affect global FLD.
  161.  
  162. procedure SET_BOOL (var bool : boolean) ;
  163.     Sets boolean to be undefined, neither true nor false.
  164.     Procedure Read_Bool will not allow user to go forward from an
  165.     undefined boolean, so this is a way to force the user to
  166.     answer Yes or No to a question that they may return to.  See
  167.     also function Defined.
  168.  
  169. procedure SHOW_MSG (msg : str_type) ;
  170.     Beeps, displays message centered on line 23, pauses (calls proc
  171.     Pause).
  172.  
  173. function STRIPCH (instr:str_type ; inchar:char) : str_type ;
  174.     Strips leading instances of the character from the string.
  175.  
  176. procedure WRITE_BOOL (bool:boolean ; col, row:integer) ;
  177.     Writes "YES" or "NO " at the column and row specified, depending on
  178.     value of the boolean.  If boolean is not defined, writes dashes.
  179.  
  180. procedure WRITE_INT (int:integer ; width,col,row:integer) ;
  181.     Writes the integer, right-justified in a field WIDTH characters
  182.     wide, at the column and row specified.
  183.  
  184. procedure WRITE_REAL (r:real ; width,frac,col,row:integer) ;
  185.     Writes the real, right-justified in decimal format with FRAC digits
  186.     to the right of the decimal point in a field WIDTH wide, at the
  187.     column and row specified.
  188.  
  189. procedure WRITE_STR (st:str_type ; col,row:integer) ;
  190.     Writes the string at the column and row specified.
  191.  
  192.  
  193. DOCUMENTATION FOR DATE22.INC ------------------------------------------
  194.  
  195. The functions and procedures in this Include file allow you to
  196. read and write dates in a fashion similar to reading and writing
  197. strings, integers, reals and booleans.  You can also perform
  198. number of other functions on dates, such as count the number of
  199. days between two dates, test for leapyear, compute the previous
  200. and next day, etc.  If you include this file, include IO22.INC
  201. first.
  202.  
  203.  
  204. GLOBAL TYPES AND CONSTANTS
  205.  
  206. const
  207.     fdslen = 29 ; { length of fulldatestring }
  208.  
  209. type
  210.     DATE = record
  211.         yr : integer ; { 0 .. 9999 }
  212.         mo : integer ; { 1 .. 12 }
  213.         dy : integer ; { 1 .. 31 }
  214.       end ;
  215.  
  216.     DATESTRING = string[10] ;  { 'MM/DD/YYYY' }
  217.  
  218.     FULLDATESTRING = string[fdslen] ;  { Date written out in words }
  219.  
  220.     JULDATE = record
  221.         yr  : integer ; { 0 .. 9999 }
  222.         day : integer ; { 1 .. 366 }
  223.       end ;
  224.  
  225.     JULDATESTRING = string[8] ; { 'YYYY/DDD' }
  226.  
  227. const
  228.     NULL_DATE     : date       = (yr:0 ; mo:0 ; dy:0) ;
  229.     NULL_DATE_STR : datestring = 'MM/DD/YYYY' ;
  230.  
  231.  
  232. PROCEDURES AND FUNCTIONS
  233.  
  234. function BUILD_FULL_DATE_STR (dt : date) : fulldatestring ;
  235.     Build printable string of current date.  For instance,
  236.     "Wednesday, May 27, 1987."
  237.  
  238. function DATE_DIFF (dt1, dt2 : date) : real ;
  239.     Computes the number of days between two dates.
  240.  
  241. function EQUAL_DATE (dt1, dt2 : date) : boolean ;
  242.     Returns True if dt1 is equal to dt2, else False.
  243.  
  244. function GREATER_DATE (dt1, dt2 : date) : integer ;
  245.     Compares two dates, returns 0 if both equal, 1 if first is
  246.     greater, 2 if second is greater.
  247.  
  248. procedure GREG_TO_JUL (dt : date ; var jdt : juldate) ;
  249.     Converts a gregorian date to a julian date.
  250.  
  251. procedure JUL_TO_GREG (jdt : juldate ; var dt : date) ;
  252.     Converts a julian date to a gregorian date.
  253.  
  254. function LEAPYEAR (yr : integer) : boolean ;
  255.     Returns True if the year is a leap year, else False.  The
  256.     year is year and century, e.g. year 1984 is '1984,' not '84.'
  257.  
  258. function MK_DT_ST (dt : date) : datestring ;
  259.     Makes a string out of a date -- used for printing dates.
  260.  
  261. function MK_JUL_DT_ST (jdt : juldate) : juldatestring ;
  262.     Makes a string out of a julian date.
  263.  
  264. function MONTH_DIFF (dt1, dt2 : date ) : integer ;
  265.     Computes number of months between two dates, rounded.
  266.  
  267. procedure NEXT_DAY (var dt : date) ;
  268.     Adds one day to the date.
  269.  
  270. procedure PREV_DAY (var dt : date) ;
  271.     Subtracts one day from the date.
  272.  
  273. procedure READ_DATE (var dt: date ; col, row: integer) ;
  274.     Read date at column and row specified.  If the user enters
  275.     only two digits for the year, the procedure plugs the century
  276.     as 1900 for years from 80 to 99 or 2000 for years from 00 to
  277.     79, but the user can enter all four digits to override the
  278.     plug.
  279.  
  280. function VALID_DATE (dt:date) : boolean ;
  281.     Returns True if the date is a valid date, else False.
  282.  
  283. procedure WRITE_DATE (dt: date ; col, row: integer) ;
  284.     Writes date at column and row specified.
  285.  
  286. function ZELLER (dt : date) : integer ;
  287.     Compute day of the week using Zeller's Congruence.  Returns 0 (Sunday)
  288.     through 6 (Saturday).
  289.