home *** CD-ROM | disk | FTP | other *** search
- ' MASKINPUT
- ' (C) 1987 By Kevin L. Curtis
- ' 12/30/87
- '
- ' Routine Name: MASKINPUT
- ' Version: 1.0
- ' Written by: Kevin L. Curtis
- ' Language: QuickBASIC 3.0
- '
- ' Purpose: A highly versatile user input routine that uses
- ' a mask$ value passed much like the picture function
- ' in some popular Data Base products.
- '
- ' Example: mask$ = "( ) - " for phone number or
- ' mask$ = space$(40) for blank field.
- '
- 'Parameters passed: row%,col%,attr%,mask$,DefaultVal$,ReturnVal$,
- ' ftype% = 0
- ' Where: row% = Row for field input.
- ' col% = Column for field input.
- ' attr% = Use ADVBAS CALL CALCATTR(foreground%,_
- ' background%,attr%) to get attr% value or
- ' (BACKGROUND * 16) + FOREGROUND = attr%.
- ' mask$ = What ever you want your field to look like.
- ' " - - " or " / / "
- ' DefaultVal$ = the default value for the field. This
- ' text will be left justified so use spaces
- ' if you want it in a special postion.
- ' ReturnVal$ = the return value form user input
- ' ftype% = 0 for alphanumeric, -1 for numeric values only
- ' Exitkey% = the ASC number of the key that exited the
- ' routine. Use this to verify special functions.
- '
- 'NEXT VERSION IMPROVEMENTS: Minimum and maximum value validation with
- ' automatic maximum validation from lenth of
- ' mask$ if no maximum value is passed. Will
- ' also allow for commas and decimal places so
- ' you can use the data returned with the PRINT
- ' USING statement.
- '
- ' NOTES: When I use this routine I define a global array for special
- ' keys. This will let you to check for HELP of Allowable ENTER
- ' or EXIT keys like: F1 - F10; TAB; CURSOR UP/DOWN PGUP/DN ect.
- ' This allows you to exit the routine and take care of a request-
- ' ed function like HELP and then return the ReturnVal$ as the
- ' DefaultVal$ putting the user back where they left via the
- ' ReturnCurrentpos% value.
- '
- 'This is a Shareware product. If you find it useful a donation of your
- 'choice 1$-10$ would be appreciated. I will be upgrading the product in
- 'the near future. How soon depends on your response.
-
- 'SEND DONATIONS AND/OR COMMENTS TO:
- '
- ' SoftwareValue FLAP ->(For Little As Possible)
- ' 7710 Swiss
- ' Rowlett, TX 75088
- ' (214)475-7586
- '
-
-
-
-
- '════════════════ These variables are a MUST for using MASKINPUT ══════════
- '************** DECLARE SOME COMMON VARIABLES **************
- COMMON slcolor%,Statrow%,Statcol%,lastkey%,normattr%,skcolor%,fieldchar%
- COMMON ReturnCurrentpos%
- '*************** DIM GLOBAL ARRAYS ****************
- DIM SHARED maskpos%(40,1), COLPOS%(80), FieldPos%(80)
- '*************** INCLUDE FILES NEEDED ********************
- REM $INCLUDE : 'STATLIN.INC' ' Contains routine for CAPS INS SCRL NUM
- REM $INCLUDE : 'getkey.INC' ' Loop for getting a key and updateing statlin
- REM $INCLUDE : 'status.inc' ' Routine for displaying Status Line Messages
- '*********************************************************
- '═══════════════════════════ END OF MUST variables ══════════════════════
-
- '************************ DEMO PROGRAM ********************
- Statrow%= 25: Statcol%=60: lastkey% = 1
- call calcattr(1,7,skcolor%):CALL CALCATTR(1,7,SLCOLOR%)
- call calcattr(15,1,normtext%): call calcattr(7,1,normattr%)
- row% = 5: col% = 10: call calcattr(1,7,attr%) : fg% = 7 : bg% = 1
- fieldchar% = 32
-
- mask$ = "( ) - " ' Our mask template for user input
- 'mask$ = space$(40) ' Example of a blank field
- DefaultVal$ = "214" ' This gives us a default area code for phone number
- ReturnVal$ = "" ' NULL new value
- color 15,1,1:cls ' Set colors and clear screen
- CALL XQPRINT("F1 FOR MORE INFORMATION - ESC TO QUIT DEMO",1,1,15,0)
- call xqprint(space$(80),25,1,skcolor%,0) 'Make sure the status line is clear
-
- '********************** SOME TEXT FOR THE DEMO *********************
- call xqprint("Parameters Passed : mask$ = "+chr$(34)+"( ) - "+chr$(34),2,26,normtext%,0)
- call xqprint("default_value$ = "+chr$(34)+"214"+chr$(34),3,47,normtext%,0)
- call xqprint("Notice the 214 default and the cursor positioned at the",5,25,normtext%,0)
- call xqprint("first available space on the field ready for your input",6,25,normtext%,0)
- call xqprint("This is the status line for INS CAPS NUM & SCRL",23,33,normtext%,0)
- call xqprint(chr$(25)+" "+chr$(25)+" "+chr$(25)+" "+chr$(25),24,62,normtext%,0)
- call xqprint("PHONE",5,4,normtext%,0)
-
- call MASKINPUT(row%,col%,attr%,mask$,DefaultVal$,ReturnVal$,-1,Exitkey%) 'CALL MASKINPUT ROUTINE
- lnth% = LEN(ReturnVal$)
- call xqprint("The length of the value phone is "+STR$(lnth%),8,25,23,0)
- call xqprint("The returned value for phone is "+ReturnVal$,9,25,23,0)
- LOCATE 15,1,0 : color 7,1,1
- m1$ = "Notice how the returned value of phone is only the raw"
- m2$ = "data that you typed in and not any part of the mask$"
- m3$ = "value that you pased to the routine."
- call xqprint(m1$,11,25,normtext%,0) : call xqprint(m2$,12,25,normtext%,0)
- call xqprint(m3$,13,25,normtext%,0)
- call xqprint("Try Ctrl "+chr$(27)+" and Ctrl "+chr$(26)+" for next and previous word",16,1,normtext%,0)
- call xqprint("Try BACKSPACE with INSERT ON and INSERT OFF. ALT-B will blank the field.",17,1,normtext%,0)
-
- mask$ = space$(60) 'Use space$(n%) function for blank mask values
- DefaultVal$ = "Very good customer. Expect large sales volume in 1988." 'default value
- call xqprint("COMMENT:",19,1,normtext%,0)
- call MASKINPUT(19,10,attr%,mask$,DefaultVal$,ReturnVal$,0,Exitkey%)
- call delay(1) 'delay 1 second
- COLOR 7,0,0 : CLS
- end 'bye bye - end of demo
- '********************* END OF DEMO PROGRAM **************************
-
-
- '************************ THE MASKINPUT ROUTINE *********************
-
- SUB MASKINPUT(row%,col%,attr%,mask$,DefaultVal$,ReturnVal$,ftype%,Exitkey%) STATIC
- SHARED normattr%,slcolor%,statrow%,skcolor%,fieldchar%,fg%,bg%
- SHARED ReturnCurrentpos%
- color fg%,bg% : Fieldlen% = LEN(mask$): blankmask$ = STRING$(Fieldlen%,fieldchar%)
- origcol% = col% : col% = col% + INSTR(DefaultVal$,chr$(fieldchar%)) - 1: noi% = 0
- mpos% = 0 : num.of.maskpos% = 0: Exitkey% = 0
-
- FOR i% = 1 TO LEN(mask$)
- a$ = MID$(mask$,i%,1)
- IF ASC(a$) = FieldChar% THEN
- noi% = noi% + 1
- FieldPos%(noi%) = origcol%-1 + i%
- tempmask$ = tempmask$ + chr$(fieldchar%)
- ELSE
- mpos% = mpos% + 1
- maskpos%(mpos%,0) = origcol%-1 + i%
- maskpos%(mpos%,1) = asc(a$)
- tempmask$ = tempmask$ + a$
- END IF
- NEXT i%
-
- mask$ = tempmask$ : tempmask$ = ""
-
- CALL XQPRINT(SPACE$(59),statrow%,1,slcolor%,0)
- CALL GETKBD(insert%,capslock%,numlock%,scrolllock%)
- CALL XQPRINT(mask$,row%,origcol%,attr%,0)
-
- IF DefaultVal$ = "" THEN
- DefaultVal$ = mask$
- ELSE
- DefaultVal$ = LEFT$(DefaultVal$,noi%)
- FOR i% = 1 TO LEN(DefaultVal$)
- CALL XqPrint(MID$(DefaultVal$,i%,1),row%,FieldPos%(i%),attr%,0)
- NEXT i%
- ReturnVal$ = DefaultVal$
- END IF
- IF ReturnCurrentpos% THEN
- currentpos% = ReturnCurrentpos% : ReturnCurrentpos%=0
- ELSE
- IF len(ReturnVal$) = noi% THEN
- currentpos% = 1
- ELSE
- currentpos% = len(ReturnVal$)+1
- ReturnVal$ = ReturnVal$ + " "
- END IF
- END IF
- LOCATE ROW%,FieldPos%(currentpos%),1
- oldReturnVal$ = ReturnVal$ : oldcurrentpos% = currentpos%
- GETKEYS:
-
- CALL GETCHAR(CH$) :IF stat% THEN CALL STATLINE("",stat%)
- IF ASC(CH$) = 27 THEN COLOR 7,0,0 : CLS : END 'Remove this and define your own meaning
- CALL GETKBD(insert%,capslock%,numlock%,scrolllock%)
- IF LEN(ch$) = 2 THEN GOTO ExtendedKeys
- ch% = ASC(ch$)
- SELECT CASE ch%
- CASE 27 'ESCAPE
- EXIT SUB ' remove or define you own meaning for Escape
- Exitkey% = 27
- CASE 9 'TAB KEY a forware movement enter key
- Exitkey% = 15 : GOTO EXITROUTINE
- CASE 13 'ENTER
- EXITROUTINE:
- pf$ = ""
- FOR i% = origcol% to (origcol%+Fieldlen%-1)
- a% = screen(row%,i%)
- pf$ = pf$+chr$(a%)
- NEXT i%
- call xqprint(pf$+space$(Fieldlen%-len(pf$)),row%,origcol%,normattr%,0)
- IF Exitkey% = 0 THEN Exitkey% = 13
- EXIT SUB
- CASE 8 'BACKSPACE
- oldReturnVal$ = ReturnVal$ : oldcurrentpos% = currentpos%
- IF currentpos% = 1 THEN GOTO GETKEYS
- lastkey% = -1
- IF insert% THEN
- ReturnVal$ = left$(ReturnVal$,currentpos%-2) + right$(ReturnVal$, LEN(ReturnVal$) - (currentpos%-1))
- FOR i% = currentpos%-1 TO LEN(ReturnVal$)
- IF i% = 0 THEN GOTO BOL2 'Check for 0 value
- call xqprint(mid$(ReturnVal$,i%,1),row%,fieldpos%(i%),attr%,0)
- BOL2:
- NEXT i%
- IF LEN(ReturnVal$) = noi% THEN
- call xqprint(chr$(fieldchar%),row%,fieldpos%(len(ReturnVal$)),attr%,0)
- ELSE
- call xqprint(chr$(fieldchar%),row%,fieldpos%(len(ReturnVal$)+1),attr%,0)
- END IF
- BOL3:
- ELSE
- ReturnVal$ = left$(ReturnVal$,currentpos%-2) + chr$(fieldchar%) + right$(ReturnVal$, LEN(ReturnVal$) - (currentpos%-1))
- call xqprint(chr$(fieldchar%),row%,fieldpos%(currentpos%-1),attr%,0)
- END IF
- GOSUB CHECKPOS
- LOCATE ,FieldPos%(currentpos%),1
- GOTO GETKEYS
- CASE ELSE
- IF ftype% = -1 THEN 'If numeric only
- IF ASC(ch$) < 48 OR ASC(Ch$) > 57 THEN
- statmssg$ = "Input must be NUMBERS ONLY"
- CALL statline(statmssg$,stat%)
- GOTO GETKEYS
- END IF
- ELSE
- IF ASC(ch$) < 32 OR ASC(Ch$) > 127 THEN GOTO GETKEYS
- END IF
- lastkey% = 1: GOTO INSCH
- END SELECT
-
- INSCH: 'VERIFY LEN OF FIELD & INSERT KEY MODE & PRINT CHARACTER
- IF insert% AND LEN(ReturnVal$) = NOI% THEN
- oldReturnVal$ = ReturnVal$ : oldcurrentpos% = currentpos%
- IF RIGHT$(ReturnVal$,1) = chr$(fieldchar%) THEN
- ReturnVal$ = left$(ReturnVal$,noi%-1)
- ELSE
- statmssg$ = "Input Field Is Full"
- CALL statline(statmssg$,stat%)
- CALL CLRKBD
- GOTO GETKEYS
- END IF
- END IF
- CALL XqPrint(ch$,row%,FieldPos%(currentpos%),attr%,0)
- IF insert% THEN
- oldReturnVal$ = ReturnVal$ : oldcurrentpos% = currentpos%
- ReturnVal$ = left$(ReturnVal$,currentpos%-1) + ch$ + right$(ReturnVal$, LEN(ReturnVal$) - (currentpos%-1))
- FOR i% = currentpos%+1 TO LEN(ReturnVal$)
- CALL XqPrint(MID$(ReturnVal$,i%,1),row%,FieldPos%(i%),attr%,0)
- NEXT i%
- ELSE
- oldReturnVal$ = ReturnVal$ : oldcurrentpos% = currentpos%
- new1$ = left$(ReturnVal$,currentpos%-1) + ch$
- if len(ReturnVal$) > len(new1$) THEN
- new2$ = right$(ReturnVal$, LEN(ReturnVal$) - (currentpos%))
- ELSE
- new2$ = ""
- END IF
- ReturnVal$ = new1$ + new2$
- END IF
- currentpos% = currentpos% + (lastkey%)
- IF currentpos% > noi% THEN currentpos% = noi%
- LOCATE ,FieldPos%(currentpos%),1
- GOTO GETKEYS
-
- ExtendedKeys: 'GET EXTENDED KEYS. ADD OR CHANGE AS YOU NEED
- extkey = ASC(RIGHT$(ch$,1))
- SELECT CASE extkey
- CASE 15 'SHIFT TAB a backware movement exit key or just a exit key
- Exitkey% = 15 : GOTO EXITROUTINE
-
- CASE 22 'Alt-U UNDO last command
- if ReturnVal$ = oldReturnVal$ then goto getkeys
- tempReturnVal$ = ReturnVal$ : tempcurrentpos% = currentpos%
- call XqPrint(mask$,row%,origcol%,attr%,0)
- IF noi% = LEN(mask$) THEN
- call XqPrint(oldReturnVal$,row%,origcol%,attr%,0)
- goto bottomofaltu
- END IF
- FOR i% = 1 TO LEN(oldReturnVal$)
- CALL XqPrint(MID$(oldReturnVal$,i%,1),row%,FieldPos%(i%),attr%,0)
- NEXT i%
- bottomofaltu:
- ReturnVal$ = oldReturnVal$ : currentpos% = oldcurrentpos%
- oldReturnVal$ = tempReturnVal$ : oldcurrentpos% = tempcurrentpos%
- locate ,fieldpos%(currentpos%),1: goto getkeys
-
- CASE 59 'F1 REDEFINE FOR YOUR OWN USE
- if sh% then color 7,1,1
- REM $INCLUDE : 'MASK.HLP' 'HELP FILE FOR DEMO ONLY
- 'ReturnCurrentpos% = Currentpos% 'This is how you return the
- 'user back to exact cursor location.
-
- CASE 72 'CURSOR UP a backward exit key
- Exitkey% = 72 : GOTO EXITROUTINE
-
- CASE 80 'CURSOR DOWN a foreward exit key
- Exitkey% = 80 : GOTO EXITROUTINE
-
- CASE 117 'Ctrl-End Delete to end of line
- oldReturnVal$ = ReturnVal$ : oldcurrentpos% = currentpos%
- ReturnVal$ = left$(ReturnVal$,currentpos%-1)+ " "
- IF mpos% = 0 THEN
- call XqPrint(space$(origcol%+LEN(mask$)-POS(0)),row%,pos(0),attr%,0)
- GOTO getkeys
- END IF
- call XqPrint(space$(origcol%+LEN(mask$)-POS(0)),row%,pos(0),attr%,0)
- FOR i% = 1 TO mpos%
- call XqPrint(chr$(maskpos%(i%,1)),row%,maskpos%(i%,0),attr%,0)
- NEXT i%
- GOTO getkeys
-
- CASE 75 'CURSOR-LEFT
- lastkey% = -1 : GOSUB CHECKPOS: LOCATE ,FieldPos%(currentpos%),1
- GOTO GETKEYS
-
- CASE 77 'CURSOR-RIGHT
- IF currentpos% < LEN(ReturnVal$) THEN
- lastkey% = 1 : GOSUB CHECKPOS: LOCATE ,FieldPos%(currentpos%),1
- GOTO GETKEYS
- ELSE
- IF RIGHT$(ReturnVal$,1) <> " " AND LEN(ReturnVal$) < noi% THEN
- ReturnVal$=ReturnVal$+" " : lastkey% = 1
- GOSUB CHECKPOS: LOCATE ,FieldPos%(currentpos%),1
- GOTO GETKEYS
- END IF
- statmssg$ = "To move past your input use the SPACE BAR"
- CALL statline(statmssg$,stat%)
- GOTO GETKEYS
- END IF
-
- CASE 71 'HOME KEY
- LOCATE ,fieldpos%(1) : currentpos% = 1 : goto getkeys
-
- CASE 79 'END KEY
- FOR char% = LEN(ReturnVal$) TO 1 STEP -1
- word$ = MID$(ReturnVal$, char%, 1)
- IF word$ <> chr$(fieldchar%) THEN
- EXIT FOR
- END IF
- NEXT char%
- IF MID$(ReturnVal$,char%+1,1) = chr$(fieldchar%) THEN
- char% = char% + 1 : GOTO BOEND
- END IF
- IF char% = LEN(ReturnVal$) AND char% <> noi% THEN
- ReturnVal$ = ReturnVal$ + chr$(fieldchar%)
- char% = LEN(ReturnVal$)
- END IF
- BOEND:
- currentpos% = char%
- lastkey% = 0
- LOCATE ,fieldpos%(currentpos%) : goto getkeys
-
- CASE 83 '**** DELETE KEY ****
- oldReturnVal$ = ReturnVal$ : oldcurrentpos% = currentpos%
- IF LEN(ReturnVal$) = 0 THEN GOTO GETKEYS
- IF currentpos% > LEN(ReturnVal$) THEN GOTO GETKEYS
- IF currentpos% > 1 THEN
- ReturnVal$ = left$(ReturnVal$,currentpos%-1) + right$(ReturnVal$, LEN(ReturnVal$) - (currentpos%))
- ELSE
- ReturnVal$ = RIGHT$(ReturnVal$,len(ReturnVal$)-1)
- END IF
- lastkey% = 0
- call xqprint(chr$(fieldchar%),row%,fieldpos%(len(ReturnVal$)+1),attr%,0)
- FOR i% = currentpos% TO LEN(ReturnVal$)
- call xqprint(mid$(ReturnVal$,i%,1),row%,fieldpos%(i%),attr%,0)
- NEXT i%
- GOSUB CHECKPOS : LOCATE ,FieldPos%(currentpos%),1 : GOTO GETKEYS
-
- CASE 116 'Ctrl-Right Arrow - Next Word
- lastkey% = 0
- wordloc% = INSTR(currentpos%+1,ReturnVal$," ")
- if wordloc% >= LEN(ReturnVal$) OR wordloc% = 0 THEN GOTO GETKEYS
- FOR char% = wordloc% TO LEN(ReturnVal$)
- word$ = MID$(ReturnVal$, char%, 1)
- IF word$ <> " " THEN
- wordloc% = char%
- EXIT FOR
- END IF
- NEXT char%
- IF wordloc% > 1 AND wordloc% > currentpos%+1 THEN currentpos% = wordloc%
- GOSUB CHECKPOS : LOCATE ,FieldPos%(currentpos%),1 : GOTO GETKEYS
-
- CASE 115 'Ctrl-left Arrow - Next Word
- CTAGAIN:
- FOR char% = currentpos% TO 1 STEP -1
- word$ = MID$(ReturnVal$, char%, 1)
- IF word$ = " " AND char% < currentpos% THEN
- EXIT FOR
- END IF
- NEXT char%
- IF currentpos% - char% = 1 THEN
- currentpos% = currentpos% - 1
- GOTO CTAGAIN
- END IF
- currentpos% = char%+1
- lastkey% = 0
- GOSUB CHECKPOS : LOCATE ,FieldPos%(currentpos%),1 : GOTO GETKEYS
-
- CASE 48 'ALT-B Blank Field
- oldReturnVal$ = ReturnVal$ : oldcurrentpos% = currentpos%
- locate ,,0 : ReturnVal$ = mask$
- CALL XqPRINT(mask$,row%,origcol%,attr%,0) :ReturnVal$ = ""
- currentpos% = 1 :locate ,fieldpos%(1),1: goto getkeys
- CASE ELSE
- GOTO GETKEYS ' GO GET ANOTHER KEY FROM USER
- END SELECT
-
- Checkpos:
- currentpos% = currentpos% + (lastkey%)
- IF currentpos% < 1 THEN currentpos% = 1
- IF currentpos% > noi% THEN currentpos% = noi%
- RETURN
- END SUB
-