home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MISC / TNH_PC.ZIP / CREBS.NL < prev    next >
Encoding:
Text File  |  1987-01-14  |  4.0 KB  |  148 lines

  1. BASIC Screen Input Routines 
  2.  
  3.               Ken Crebs
  4.  Greater Cincinnati Ohio Users Group
  5.  
  6. I have developed a generalized
  7. screen input subroutine in BASIC
  8. that I use extensively.  Its
  9. capability to be customized makes it
  10. especially useful.
  11.  
  12. The subroutine requires the
  13. following variables to be
  14. initialized:
  15.  
  16. o   the row and column where the
  17.     input is to start.
  18. o   the maximum length of the input.
  19. o   the type of input.
  20.     (Alphanumeric, Integer, or Real)
  21.  
  22. The subroutine uses the INKEY$
  23. variable to examine each character
  24. as it is entered from the screen.
  25. The ASC function is used to validate
  26. each input character as it is stored
  27. in the variable INP.STR$.  Numeric
  28. type data is converted using the VAL
  29. function.  The left and right arrows
  30. on the numeric keypad are used to
  31. move the cursor within the field
  32. without affecting the contents.
  33. When the cursor goes beyond the
  34. specified maximum length, it is
  35. returned to the beginning of the
  36. field.  The backspace key will erase
  37. the contents one character at a
  38. time.
  39.  
  40. The subroutine returns the status of
  41. three different cases.  The variable
  42. RTRN% is set to:
  43.  
  44. 0 = Nothing was entered in the
  45. field, <Enter> was pressed.
  46. 1 = Normal operation, Data was
  47. entered and <Enter> was pressed.
  48. 9 = The <Esc> key was pressed.
  49. Usually means abort or start over.
  50.  
  51. The subroutine GENIN is listed at
  52. lines 10000-10330.  The
  53. demonstration program calls GENIN
  54. and displays the status of the call
  55. and the contents of the variable
  56. INP.STR$.  When the program pauses
  57. (Break in 90), the values of KROW%,
  58. KCOL%, KLEN%, KTYP$, and KSIGN% can
  59. be changed and the CONT command used
  60. to resume execution.
  61.  
  62. The subroutine will handle most
  63. screen input situations, but it can
  64. also be modified for special cases
  65. fairly easily.
  66.  
  67. Here are a few special cases and the
  68. suggested modifications:
  69.  
  70.  
  71. 1.  Recognition of special keys
  72.     being pressed: <Ins>, <Del>,
  73.     <F1>, <F2>, etc.  The ASCII
  74.     codes for these keys can be
  75.     found on page G-7 in the
  76.     appendix of the BASIC Reference
  77.     Manual.  For example, to
  78.     recognize the function key <F1>,
  79.     I would add the line:
  80.  
  81.     10115 IF CS$=CHR$(0)+CHR$(59)
  82.     THEN LOCATE ,,0:RTRN%=2:RETURN
  83.     '<F1>
  84.  
  85.     The calling program would then
  86.     check for a RTRN% value of 2 and
  87.     take the appropriate action.
  88.  
  89.     * Note:  The <F1> function key
  90.     must be disabled first.  I
  91.     usually disable all the function
  92.     keys at the beginning of my
  93.     program like this:
  94.  
  95.     KEY OFF:FOR I%=1 TO 10:KEY
  96.     I%,"":NEXT
  97.  
  98. 2.  Recognition of a specific input
  99.     or a range of inputs.  Use the
  100.     variable KTYP$ to define a new
  101.     data type.  For example, to
  102.     recognize only the input of a
  103.     "Y" or and "N", I would define a
  104.     new data type, say KTYP$="q".
  105.     Then add the line:
  106.  
  107.     10165  IF KTYP$="q" THEN IF
  108.     (ACODE%<>89 AND ACODE%<>121 AND
  109.     ACODE%<>78 AND ACODE%<>110) THEN
  110.     BEEP:GOTO 10080 ELSE GOTO 10200
  111.  
  112.     * Note: In the demonstration
  113.     program set KLEN%=1 AND
  114.     KTYP$="Q".
  115.  
  116. 3.  Audible recognition when the end
  117.     of the input field is reached.
  118.     Remove the comment on line 10060
  119.     and the subroutine will sound a
  120.     low beep when the cursor has
  121.     gone past the end of the input
  122.     field.
  123.  
  124. 4.  Automatic conversion of
  125.     lowercase characters to
  126.     uppercase.  Add the line:
  127.  
  128.     10195 IF ACODE%>96 THEN
  129.     CS$=CHR$(ACODE%-32)
  130.  
  131. If you want to input multiple
  132. fields, use a loop to make repeated
  133. calls to GENIN with each field's
  134. attributes stored in arrays.  I
  135. think you can see the versatility of
  136. having the screen input function in
  137. one place.  I hope this subroutine
  138. will be as useful to you as it is to
  139. me.
  140.  
  141. [ Editor's Note:  The program is
  142. rather lengthy so the source is not
  143. listed here.  However, the source
  144. exists as a separate file on this
  145. newsletter diskette and may be
  146. copied to your work diskette. The
  147. source file name is: SCREEN.BAS ]
  148.