PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Marco Ruiz on March 18, 2009, 05:37:49 PM

Title: Edit with mask
Post by: Marco Ruiz on March 18, 2009, 05:37:49 PM
Hay alguna forma de utilizar un edit control con mask, por ejemplo, para el ingreso de fechas "##/##/####" ?
Title: Re: Edit with mask
Post by: Marco Ruiz on March 18, 2009, 05:41:37 PM
There is some way of using an edit control with mask, for example, for the data input of dates "##/##/####" ?
Title: Re: Edit with mask
Post by: Mark Strickland on April 14, 2009, 06:41:01 PM
I have built an edit routine that is not exactly a mask.  See below for the masks/codes.  During data entry you can only type the specified characters and the appropriate place.  There is a function used to setup the format for a field.  There are other functions calls that go in the KILLFOCUS event and the WM_CHAR events of a text box.  The KILLFOCUS event does some post editing like right justifying numbers.  The WM_CHAR event handles the character classes and rejects things like alpha in a numeric field at the keystroke level.

Here is how it works:

Example (v5.2) signed number
You can only type a dash if it is the FIRST character otherwise you get a beep.
You can only type digits and a decimal point.
After you type the first 5 digits only a decimal is allowed.
After you type the decimal only 2 more digits are allowed.
Everthing else BEEPS.

There are masks/codes for lots of common input needs.

I would be willing to share this code but it may take you a little tinkering to get it working in your project.


FUNCTION EditMaskSetup( _
          BYVAL hWndForm    AS DWORD, _  ' handle of Form
          BYVAL hWndControl AS DWORD, _  ' handle of Control
          BYVAL cMask       AS STRING _  ' edit mask
          ) AS LONG

'Call this from <textbox>_EN_SETFOCUS to setup the control mask.
'  IF the TAG parm IS specially formated this is not necessary because it is picked up from the TAG
'  If the TAG parm for a field contains 'F=' parm then that is used to setup the field
'  If anytime the MASKEDIT function is called and the ccmask(100) does not match the TAG value the
'  field setup is re-done and the mask is put into ccmask(100).
'
'  ssn    = ddd-dd-dddd
'  SSN    = ddddddddd     (post edited - ddd-dd-dddd)
'  NDC    = ddddddddddd   (post edited - ddddd-dddd-dd)
'  DEA    = AAddddddd     (post edited with digit part validated with check digit logic
'  EMAIL  = id@domain.zzz (no spaces, one @, one . in domain, something must follow . in domain (max 40 char)
'  phone  = ddd/ddd-dddd
'  PHONE  = dddddddddd    (post edited - ddd/ddd-dddd)
'  date1  = mm/dd/yyyy
'  DATE1  = mmddyyyy      (post edited - mm/dd/yyyy)
'  a(5)   = alpha lower case
'  A(5)   = alpha upper case
'  P(5)   = proper name   (like S except first letter preceeded by space is caps)
'  M(5)   = alpha mixed case
'  S(5)   = any string
'  T(5)   = any string with alpha UPSHIFTED
'  t(5)   = any string with alpha DOWNSHIFTED
'  V(5.2) = value with decimal ddddd.dd
'  v(5.2) = value with decimal ddddd.dd can be negative
'  Z(7)   = numeric zero fill left
'  RX     = Special variant of Z(7) for RX numbers that allows * in position one
'  C(5)cc = Custom character list
'  U(5)cc = sames as C except ALWAYS UPSHIFTED
'  L(5)cc = sames as C except ALWAYS DOWNSHIFTED
'