Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
KeyPress and non chars/digits
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
01110355
Message ID:
01110406
Vues:
12
Hi Naomi,

>This should be an easy question, I hope. In the class KeyPress method I want to perform code only if I typed letter or digit (in any language). If I pressed Pg Up or Del or Tab, etc., I want KeyPress to behave normally.
>
>So, my question is: how can I figure out, if I'm pressing special chars or letters/numbers?
>

I have this old textbox class that I've developed in VFP7. I hope it would help!
DEFINE CLASS txtHourMin AS TextBox
   Format = "!"
   InputMask = "99:99 AA"

   ******************************************
   FUNCTION KeyPress
   LPARAMETERS nKeyCode, nShiftAltCtrl
   ******************************************
   LOCAL lnSelStart, lcChr, llRefresh, llHr24
   lcChr = UPPER(CHR(nKeyCode))
   lnSelStart = This.SelStart
   llRefresh = .F.
   llHr24 = .F.
   IF INLIST(nKeyCode, 59, 58)   && ";" and ":"
      This.SelStart = 3
      NODEFAULT
   ELSE
      IF ISALPHA(lcChr) 
         IF INLIST(lcChr, "A", "P")
            This.Value = LEFT(This.Value, 5) + " " + lcChr + "M"
            llRefresh = .T.
         ENDIF
         NODEFAULT
      ELSE
         IF INLIST(nKeyCode, 59, 58)   && ";" and ":"
            This.SelStart = 3
            NODEFAULT
         ENDIF
      ENDIF
   ENDIF
   IF llRefresh
      This.Refresh()
      This.SelStart = lnSelStart
   ENDIF
   RETURN .T.

   *************************************
   FUNCTION Valid
   *************************************
   LOCAL llReturn, lcThisVal, lcStripVal, ltVal, lcTime
   lcThisVal = UPPER(This.Value)
   lcStripVal = CHRTRAN(lcThisVal, ":", "")
   llReturn = .T.
   ltVal = CTOT(lcThisVal)
   IF EMPTY(ltVal)
      llReturn = EMPTY(lcStripVal)
   ELSE
      IF NOT ISDIGIT(ALLTRIM(LEFT(lcStripVal, 2)))
         llReturn = .F.
      ELSE
         lcTime = TTOC(ltVal, 2)
         This.Value = ALLTRIM(LEFT(lcTime, 5) + SUBSTR(lcTime, AT(" ", lcTime)))
         This.Refresh()
      ENDIF
   ENDIF
   RETURN (llReturn)

   *************************************
   FUNCTION CTimeToHM
   LPARAMETERS tcTime
   *************************************
   LOCAL ltVal, lcThisVal, lcReturn
   lcReturn = ""
   IF VARTYPE(m.tcTime) = "T"
      ltVal = m.tcTime
   ELSE
      IF VARTYPE(m.tcTime) <> "C"
         lcThisVal = UPPER(This.Value)
      ELSE
         lcThisVal = UPPER(m.tcTime)
      ENDIF
      ltVal = CTOT(m.lcThisVal)
   ENDIF
   IF EMPTY(ltVal)
      lcReturn = ""
   ELSE
      lcReturn = PADL(LTRIM(STR(HOUR(ltVal), 2)), 2, "0") + PADL(LTRIM(STR(MINUTE(ltVal), 2)), 2, "0")
   ENDIF
   RETURN (lcReturn)

   *************************************
   FUNCTION HMtoCtime
   LPARAMETERS tcHHMM
   *************************************
   LOCAL ltVal, lcThisVal, lcReturn, lcTime
   lcReturn = ""
   lcThisVal = PADL(m.tcHHMM, MAX(LEN(tcHHMM), 4))
   ltVal = CTOT(LEFT(m.lcThisVal, 2) + ":" + SUBSTR(m.lcThisVal, 3))
   IF EMPTY(ltVal)
      lcReturn = ""
   ELSE
      lcTime = TTOC(ltVal, 2)
      lcReturn = ALLTRIM(LEFT(lcTime, 5) + SUBSTR(lcTime, AT(" ", lcTime)))
   ENDIF
   RETURN (lcReturn)
ENDDEFINE
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform