home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR7
/
FOXTAILS.ZIP
/
MKEY.PRG
< prev
next >
Wrap
Text File
|
1992-04-12
|
11KB
|
312 lines
FUNCTION Mkey
PARAMETER Vrnm, Vr, VrGt, Lnth
* Written by R.L. Coppedge
* Copyright 1992 dbF Software Productions
* By the way, dbF also has:
* SysTrak A Computer Hardware/Software Inventory System
* Flags A Flatfile Application Gen. for db3,4 and Fox
* ClasAdz A Classified/Notice system for Networks
* FoxTails A collection of FoxPro tools (like this one)
* Contact dbF for more information.
* dbF Software Productions
* P.O. Box 37194
* Cleve., Ohio 44137-0194
* CIS: 72117,165
* (216)491-4581
*
* This code may be modified, but leave this original notice up
* here intact, if ya don't mind. (Add your own comments about
* how much better you made it if you like)
* What this function does is allows a user to do a majority of
* data entry from the mouse, including character entry. It
* isn't a VALIDation, per se, but an entry piece. See the sample
* code Foxtails.Prg for an example of how this would all work.
* The parameters are stated as such:
* Mkey((<expC1>, <expC2> , <expL1> [, <expN>])
* Where:
* expC1 is the name of the field
* expC2 is the initial starting value
* expL1 is it a GET? (a .F. means it's a STORE)
* expN1 is the maximum length (for Chr and numeric only)
*
ON KEY LABEL RIGHTMOUSE
IF Vrgt && If it's a GET, just read what it is...
Vrnm = VARREAD()
Vr =EVALUATE(Vrnm)
DO CASE
CASE TYPE(Vrnm) = "C"
Lnth = LEN(Vr)
CASE TYPE(Vrnm) = "L"
Lnth = 1
CASE TYPE(Vrnm) = "D"
Lnth = 8
CASE TYPE(Vrnm) = "N" && Can't figure out a good way to do this
Lnth = 14 && 14? Yeah, that sound good
ENDCASE
ENDIF
CLEAR TYPEAHEAD
* Time to declare
PRIVATE Tp, Msg, A1,A2,A3,A4,A5,A6,A7,A8,A9,A10
PRIVATE Lim, Shft, Alt, Ctrl, Shftlck, Ret, Esc, X, Y
DECLARE Ln(7,2), A(5)
Tp = TYPE('Vr') && What type of critter are we dealing with?
IF Tp $ "CFN" AND TYPE('Lnth') = "N" && Size limit on entered field
Lim = Lnth
ELSE
Lim = 0
ENDIF
Tk = SET("Talk")
SET TALK OFF
DO CASE
CASE Tp = "C"
Msg = TRIM(Vr)
CASE Tp = "D"
Msg = DTOC(Vr)
CASE Tp $ "FN"
Msg = ALLTRIM(STR(Vr))
CASE Tp = "L"
Msg = IIF(Vr,"Y","N")
ENDCASE && Regardless of original type, we treat 'em all equal...
* like they was true characters...
DEFINE WINDOW Dsplay FROM 6,0 TO 8,79 TITLE "Entered Data"
ACTIVATE WINDOW Dsplay && This window shows what they've got so far
@0,0 SAY Msg + ""
DEFINE WINDOW Keyb FROM 9,0 TO 18,60 DOUBLE TITLE "Mouse_Key" FLOAT
ACTIVATE WINDOW Keyb && This is the pseudo-keyboard
Ln(1,1) = "<E> F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12"
Ln(2,1) = " ` 1 2 3 4 5 6 7 8 9 0 - = \ "
Ln(3,1) = " <T> q w e r t y u i o p [ ]"
Ln(4,1) = " a s d f g h j k l ; ' ┘"
Ln(5,1) = " <CL> z x c v b n m , . /"
Ln(6,1) = " <S> <C> <A> |---SPACE---| \"
* Ln(#,1) shows what the Kb looks like when Shft is .F. (lowe-case)
* Ln(#,2) shows what the Kb looks like when Shft is .T. (upper-case)
Ln(1,2) = "<E> F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12"
Ln(2,2) = " ~ ! @ # $ % ^ & * ( ) _ + | "
Ln(3,2) = " <T> Q W E R T Y U I O P { }"
Ln(4,2) = ' A S D F G H J K L : " ┘'
Ln(5,2) = " <CL> Z X C V B N M < > ?"
Ln(6,2) = " <S> <C> <A> |---SPACE---| |"
A(1) = "'1234567890-=\"
A(2) = "qwertyuiop[]"
A(3) = "asdfghjkl;'"
A(4) = "zxcvbnm,./"
A(5) = "~!@#$%^&*()_+|"
* A(#) is the array we use to determine the exact key "hit"
STORE .F. TO Shft, Alt, Ctrl, Shftlck, Ret, Esc
DO WHILE .T. && our entry loop (I know...we're not supposed
* to use DW.T.'s anymore...)
CLEAR && Reset the Kb
FOR X = 1 TO 6
@X,0 SAY Ln(X,IIF(Shft,2,1))
ENDFOR
@7,0 SAY "<E>scape, <T>ab, <CL>Caps Lock, <S>hift, <C>ontrol, <A>lt"
@1,0 GET A1 PICTURE "@*IHT ;;;;;;;;;;;;" SIZE 1,3,1 DEFAULT 0 VALID KVal(A1,"1")
@2,4 GET A2 PICTURE "@*IHT ;;;;;;;;;;;;;;" SIZE 1,2,1 DEFAULT 0 VALID KVal(A2,"2")
@3,2 GET A3 PICTURE "@*IHT" SIZE 1,3,1 DEFAULT 0 VALID KVal(A3,"3")
@3,7 GET A4 PICTURE "@*IHT ;;;;;;;;;;;" SIZE 1,3,1 DEFAULT 0 VALID KVal(A4,"4")
@4,8 GET A5 PICTURE "@*IHT ;;;;;;;;;;;" SIZE 1,3,1 DEFAULT 0 VALID KVal(A5,"5")
@5,2 GET A6 PICTURE "@*IHT" SIZE 1,4,1 DEFAULT 0 VALID KVal(A6,"6")
@5,9 GET A7 PICTURE "@*IHT ;;;;;;;;;" SIZE 1,3,1 DEFAULT 0 VALID KVal(A7,"7")
@6,2 GET A8 PICTURE "@*IHT ;;" SIZE 1,3,3 DEFAULT 0 VALID KVal(A8,"8")
@6,20 GET A9 PICTURE "@*IHT" SIZE 1,13,1 DEFAULT 0 VALID KVal(A9,"9")
@6,37 GET A10 PICTURE "@*IHT" SIZE 1,3,1 DEFAULT 0 VALID KVal(A10,"10")
* It's all done with mirrors....er, invisible boxes...
READ CYCLE
IF LASTKEY() = 27 OR Ret OR Esc
EXIT && They hit escape (real {27}, imagined {esc}) or Return
ENDIF
ENDDO
RELEASE WINDOW Dsplay, Keyb
IF LASTKEY() = 27 OR Esc && Escape, return original value
IF Tk = "ON"
SET TALK ON
ENDIF
IF Vrgt && Was it a GET or a STORE
SHOW GETS
ON KEY LABEL RIGHTMOUSE DO Mkey WITH "","",.T.,0
RETURN && A Get lies here!
ELSE
ON KEY LABEL RIGHTMOUSE DO Mkey WITH "","",.T.,0
RETURN Vr && A Store
ENDIF
ENDIF
* Otherwise, we need to pass the new value...
* 1st we need to convert the data type back to what it was originally
DO CASE
CASE Tp = "C"
Passit = Msg
CASE Tp = "D"
Passit = CTOD(Msg)
CASE Tp $ "FN"
Passit = VAL(Msg)
CASE Tp = "L"
Passit = Msg$"YyTt1"
ENDCASE
IF Tk = "ON"
SET TALK ON
ENDIF
IF Vrgt && If it's a GET
&Vrnm. = Passit
SHOW GETS
ON KEY LABEL RIGHTMOUSE DO Mkey WITH "","",.T.,0
RETURN
ENDIF
ON KEY LABEL RIGHTMOUSE DO Mkey WITH "","",.T.,0
RETURN Passit
* End of main procedure Code for Mkey
FUNCTION KVal
PARAMETERS X, Y
* Y is the the row that they hit, X is the column
* What the heck did they really select? I dunno, let's find out!
PRIVATE Mm, Dd, Yy, Fd, Gd, Adltr
Adltr = "" && This is the variable that holds the value selected
DO CASE
CASE Y == "1"
Esc = (X=1) && If it's 1, they hit Escape
* Here's where you could get cute, and add additional code for
* what would come out for each of the Function keys or their
* Combinations...
CASE Y == "2"
IF X <> 15
Adltr = IIF(Shft,SUBSTR(A(5),X,1),SUBSTR(A(1),X,1))
ELSE && Backspace, delete rightmost character
IF LEN(Msg) > 0 && if it exists, that is...
Msg = LEFT(Msg,LEN(Msg)-1)
ENDIF
ENDIF
CASE Y == "3" && Tab...just a tab
Adltr = chr(0) && What the #%^#$^ is a tab Char?
CASE Y == "4"
IF X <= 10
* Check to see which key they hit. If it's <= 10, either
* upper or lower case "qwertyuiop" depending on Shft
Adltr = IIF(Shft,UPPER(SUBSTR(A(2),X,1)),SUBSTR(A(2),X,1))
ELSE
* Otherwise, it's either [] or {}, again depending on the key
* hit (X) and the shift status (Shft)
Adltr = IIF(X=11 AND Shft,"{",IIF(X=11 AND !Shft,"[",IIF(X=12 AND Shft,"}","]")))
ENDIF
CASE Y == "5"
DO CASE
CASE X <= 9
* In this case, check to see X <= 9, which'll cause either
* upper or lower case "asdfghjkl" depending on Shft
Adltr = IIF(Shft,UPPER(SUBSTR(A(3),X,1)),SUBSTR(A(3),X,1))
CASE X = 12 && They've hit "Enter"...they're done...maybe
Fd = .T.
IF Tp = "D" && If it's a date, did they do good?
Gd = .T.
IF AT("/",Msg,1) <> 1 AND AT("/",Msg,2) <> LEN(Msg) AND ;
AT("/",Msg,2) <> 0 AND BETWEEN(AT("/",Msg,2) - AT("/",Msg,1),2,3)
* check for # of /'s, spacing, etc.
mm = VAL(LEFT(Msg,AT("/",Msg,1)))
dd = VAL(SUBSTR(Msg,AT("/",Msg,1)+1,AT("/",Msg,2)-1))
yy = VAL(RIGHT(Msg,LEN(Msg)-AT("/",Msg,2)))
IF BETWEEN(Mm,1,12) && Good month?
Dys = IIF(INLIST(Mm,4,6,9,11),30,31)
IF Mm = 2 && Oh, yeah...February
Dys = IIF(Yy/4=INT(Yy/4) AND Yy/1000 <> INT(Yy/1000) ,29,28)
ENDIF
Gd = BETWEEN(Dd,1,Dys) && Good days?
ENDIF
ELSE
Gd = .F.
ENDIF
IF !Gd
WAIT "Uh...valid dates are mm/dd/yy" WINDOW
Fd = .F.
ENDIF
ENDIF
Ret = Fd
OTHERWISE
Adltr = IIF(X=10 AND Shft,":",IIF(X=10 AND !Shft,";",IIF(X=11 AND Shft,'"',"'")))
* must be :;'"...onea them guys
ENDCASE
CASE Y == "6" && Shift lock toggle
IF Shftlck
Shft = .F.
Shftlck = .F.
ELSE
Shft = .T.
Shftlck = .T.
ENDIF
CASE Y == "7"
IF X <= 7
Adltr = IIF(Shft,UPPER(SUBSTR(A(4),X,1)),SUBSTR(A(4),X,1))
* In this case, check to see X <= 7, which'll cause either
* upper or lower case "zxcvbnm" depending on Shft
ELSE
Adltr = IIF(X=8 AND Shft,"<",IIF(X=8 AND !Shft,",",IIF(X=9 ;
AND Shft,">",IIF(X=9 AND !Shft,".",IIF(X=10 AND Shft,"?","/")))))
* 8, 9, 10 could be ,< .> /?
ENDIF
CASE Y == "8" && Either Shift, Control, or Alt.
Shft = (X=1) && Shift only works for the next key.
Ctrl = (X=2) && Control and Alt don't do anything,
Alt = (X=3) && actually...but that could change
* in future releases
CASE Y == "9" && Space...the final...never mind...
Adltr = " "
CASE Y == "10" && On my keyboard this little suckers stuck
Adltr = IIF(Shft,"|","\") && on the lower right...
ENDCASE
IF Y <> "8" && Check the status keys...
Shft = Shftlck
Ctrl = .F.
Alt = .F.
ENDIF
* Now, depending on the type of variable, we'll add it to the
* Msg field...wow!
IF !EMPTY(Adltr) OR Adltr = " " && Since Fox thinks " " is empty
DO CASE
CASE Lim > 0 AND LEN(Msg) >= Lim && Check length if necessary
WAIT "Entry Is Limited to " + ALLTRIM(STR(Lim)) + " Chars...Too long!" WINDOW
CASE Tp = "C" && if it's a character, just add field
Msg = Msg + Adltr
CASE Tp = "L" AND !Adltr $ "YyTt1NnFf0" && How do you say Yup?
WAIT "Logicals need to be YyTt1 (for True) or NnFf0 (No)!" WINDOW
CASE Tp = "L" AND LEN(Msg) = 1 && And how long?
WAIT "Logicals are only 1 character long (YyTt1NnFf0)" WINDOW
CASE Tp = "L" && If it got this far it's ok by me!
Msg = Adltr
CASE Tp $ "FN" AND !Adltr $ "1234567890." && #'s for #'s
WAIT "Numbers need to be, well...y'know, numbers..." WINDOW
CASE Tp $ "FN" AND Adltr = "."
IF AT(".",Msg) <> 0 && if there's already a decimal point
Msg = STUFF(Msg,AT(".",Msg),1,"")+"." && we need to move it!
ELSE
Msg = Msg + "."
ENDIF
CASE Tp $ "FN"
Msg = Msg + Adltr
CASE Tp = "D" AND !Adltr $ "1234567890/" && Bad stuff for dates!
WAIT "Dates are in the form of mm/dd/yy..." WINDOW
CASE Tp = "D" && Must be good for dates!
* Here I don't bother checking for valid dates...I do that
* at the end.
Msg = Msg + Adltr
ENDCASE
ENDIF
ACTIVATE WINDOW Dsplay
* Show the world the wonderful things we just did...and gloat
* just a tad.
CLEAR
@0,0 SAY Msg + ""
ACTIVATE WINDOW Dsplay
RETURN .T.