home *** CD-ROM | disk | FTP | other *** search
- cls
- mask$ ="Phone (###) ###-####"
- color 0,7
- ans$ = "3035551212" ' <--- data does not need to be pre-formatted
- retcode% = 0 ' <--- complete entry NOT required
- CALL MaskInput$(12,20,mask$,ans$,retcode%)
- locate 21,20 : color 7,0
- ? ans$
- ans$="123-45-67" ' <--- try incomplete/required field
- locate 13,20:? "SocSec No: "; ' rtecode% NOT changed from prev. call
- CALL MaskInput$(13, pos(0), "###-##-####",ans$,retcode%)
- locate 22,20:? ans$
- ans$=left$(date$,2) + mid$(date$,4,2) +mid$(date$,9,2)
- locate 14,20 : ?"Date: ";:lastkey% = 1
- CALL MaskInput$(14,pos(x),"##-##-##",ans$,retcode%)
- locate 23,20 : color 7,0
- ? ans$;
- print lastkey%
- end
-
- SUB MaskInput(row%, col%, mask$,ans$,mustfill%)
- '┌──────────────────────────────────────────────────────────────┐
- '│ Mask numeric input only ! - good for Social Security #'s, │
- '│ dates, telephone numbers, etc. You can use a prompt as │
- '│ part of the mask, but the prompt will be returned as part │
- '│ of the data. On exit mustfill% will contain exitkey% to │
- '│ allow test for terminating key. A negative value indicates │
- '│ an extended keycode/function key. To defeat mustfill% code, │
- '│ the user can/must SPACE thru entire entry. │
- '└──────────────────────────────────────────────────────────────┘
- LOCAL x%, y%
- %right = 1:%left = -1
- 'col% = pos(x)
- anslen% = LEN(mask$)
- old$ = ans$ : fillchar% = ASC("▒") ' <--- use your own preference
- CALL DispMask(row%, col%, mask$, ans$, fillchar%)
- CALL fbmove(mask$, x%, anslen%, %right)
- DO
- LOCATE row% ,col% + x%-1,1
- WHILE NOT instat:WEND
- w$ = inkey$
- IF LEN(w$) = 2 THEN
- w% = ASC(RIGHT$(w$,1))
- SELECT CASE w%
- CASE 75 : CALL fbmove(mask$, x%, anslen%, %left)
- CASE 77 : CALL fbmove(mask$, x%, anslen%, %right)
- CASE 71 : CALL fbmove(mask$, x%, anslen%, 0)
- CASE 79 : CALL fbmove(mask$, x%, anslen%, anslen%)
- CASE 83 'Del
- MID$(ans$, x%, 1) = chr$(fillchar%)
- ? CHR$(fillchar%);
- CASE ELSE
- exitkey% = -w%
- END SELECT
- ELSE
- SELECT CASE w$
- CASE chr$(8)
- IF x% >1 THEN
- w$ = CHR$(fillchar%)
- CALL fbmove(mask$, x%, anslen%, %left)
- LOCATE ,col% + x%-1,1
- MID$(ans$, x%, 1) = w$:? w$;
- ELSE
- BEEP
- END IF
- CASE chr$(13) : exitkey% = 13
- CASE CHR$(27) 'Escape
- ans$ = old$ : exitkey% = 27
- CASE "0" to "9", " "
- MID$(ans$, x%, 1) = w$:?w$;
- CALL fbmove (mask$, x%, anslen%, %right)
- CASE ELSE : BEEP
- END SELECT
- END IF
- IF exitkey% AND mustfill% THEN
- IF INSTR(ans$, CHR$(fillchar%)) THEN
- BEEP:exitkey% = 0:row% = CSRLIN
- LOCATE 24,1:? "Incomplete entry ! ";
- LOCATE row%
- END IF
- END IF
- LOOP until exitkey%
- mustfill% = exitkey%
- REPLACE CHR$(fillchar%) WITH " " IN ans$
- END SUB
-
- SUB DispMask(r%, c%, mask$, ans$, fillchar%)
- LOCAL x%, y%, z%, MaskValue$, ans2$
- MaskValue$ = "#"
- ans2$ = space$(LEN(mask$))
- IF LEN(ans$) = LEN(mask$) THEN z%=1
- FOR x% = 1 TO LEN(mask$)
- IF z% OR instr(MaskValue$, MID$(mask$, x%, 1)) THEN
- DO
- incr y% : IF y% > LEN(ans$) THEN ch$="":EXIT LOOP
- ch$ = MID$(ans$, y%, 1)
- LOOP WHILE instr("0123456789", ch$)=0
- ELSE
- ch$ = MID$(mask$, x%,1)
- END IF
- IF ch$="" THEN ch$ = CHR$(fillchar%) '"▒"
- MID$(ans2$, x%, 1) = ch$
- NEXT
- LOCATE r%,c%
- ans$ = ans2$
- ? ans$;
- END SUB
-
- SUB fbmove(mask$, x%, anslen%, move%)
- IF move% = 0 THEN x%=0:move% = 1
- IF move% >=anslen% THEN x% = anslen%
- IF move% < 0 and instr(LEFT$(mask$, x%-1),"#")=0 THEN EXIT SUB
- DO
- x% = x% + move%
- x% = max%(x%,0)
- x% = min(x%,anslen%)
- IF x% = 0 OR x% = anslen% THEN EXIT LOOP
- IF instr("#", MID$(mask$, x% ,1)) THEN EXIT LOOP
- LOOP
- END SUB