home *** CD-ROM | disk | FTP | other *** search
/ Current Shareware 1994 January / SHAR194.ISO / dos_util / v12n19.zip / BLINDE.BAS next >
BASIC Source File  |  1993-01-10  |  2KB  |  77 lines

  1. '********** BLINDENT.BAS
  2.  
  3. 'Kirk Woodward
  4. '
  5. 'Subprogram and demo shows how to accept passwords and other text
  6. 'without echoing it to the screen.
  7.  
  8. DEFINT A-Z
  9. DECLARE SUB BlindEnter (Text$, Row, Column)
  10.  
  11. CLS
  12. LOCATE 10
  13. PRINT "Enter some data:"
  14.    
  15. Text$ = SPACE$(10)              'set the maximum field length
  16. COLOR 0, 7                      'input with reverse colors
  17. CALL BlindEnter(Text$, 10, 19)
  18. COLOR 7, 0
  19.  
  20. LOCATE 15, 1
  21. PRINT "You entered: "; Text$
  22.  
  23. SUB BlindEnter (Text$, Row, Column)
  24.  
  25.   '  Where:  Text$   =  The entered string (returned to caller)
  26.   '          Row     =  The line where the data is entered
  27.   '          Column  =  The left column where the data is entered
  28.   '
  29.   '  At entry, BlindEnter expects Text$ to be filled with spaces in
  30.   '  order to know the maximum length of the field.
  31.   '
  32.   '  CHR$(176) = ░ is displayed in place of the actual key stroke,
  33.   '  but that can be changed to anything you like in the code below.
  34.   '
  35.   '  The only editing key that is accepted is the backspace key.
  36.  
  37.   MaxLength = LEN(Text$)        'save the incoming string length
  38.   Text$ = ""                    'then clear it to start fresh
  39.  
  40.   DO
  41.  
  42.     LOCATE Row, Column, 0
  43.     PRINT Display$; SPC(MaxLength - LEN(Display$));
  44.     IF LEN(Text$) = MaxLength THEN EXIT SUB
  45.    
  46.     DO
  47.       K$ = INKEY$
  48.     LOOP UNTIL LEN(K$)                  'wait for a keypress
  49.  
  50.     SELECT CASE ASC(K$)                 'handle keys as needed
  51.  
  52.       CASE 13, 27                       'Enter or Escape keys
  53.         EXIT SUB
  54.      
  55.       CASE 8                            'backspace key
  56.         IF LEN(Display$) >= 1 THEN
  57.           Display$ = LEFT$(Display$, LEN(Display$) - 1)
  58.           Text$ = LEFT$(Text$, LEN(Text$) - 1)
  59.         ELSE
  60.           BEEP
  61.         END IF
  62.  
  63.       CASE ELSE
  64.         IF ASC(K$) >= 32 THEN           'accept character keys only
  65.           Text$ = Text$ + K$
  66.           Display$ = Display$ + CHR$(176)
  67.         ELSE
  68.           BEEP
  69.         END IF
  70.  
  71.     END SELECT
  72.  
  73.   LOOP
  74.  
  75. END SUB
  76.  
  77.