Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Set InputMask programatically
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00392851
Message ID:
00392994
Vues:
10
Hi James.

>> I want to set the InputMask (XXXX) for a textbox at runtime using another object property to determine the length (nNumber) of the mask. I have tried putting "REPLICATE('X',nNumber) directly onto the properties InputMask line and also into the expression builder. Both generate errors. How can I do this so that the user is only permitted to enter nNumber of characters of the 'X' lind? <<

Here is a fairly generic way to set the inputMask for your textboxes. You can put it in the class and forget about it:
LOCAL 	lcAlias, lcField, lcType, laFields[1], ;
	lnElement, lnRow, lcIntegerPart, lcDecimalPart

WITH This
  IF ! EMPTY( .ControlSource ) AND ( '.' $ .ControlSource )
    IF EMPTY( .InputMask )
      *** Only set the inputmask for numeric and character fields
      *** and check the data type of the underlying field so we
      *** can set it appropriately
      lcType = TYPE( This.ControlSource )
      IF INLIST( lcType, 'C', 'N', 'I', 'Y' )
	*** Parse the alias and the field name from the ControlSource
   	lcAlias    = JUSTSTEM( .ControlSource )
	lcField    = JUSTEXT ( .ControlSource )
	*** Don't attempt to check the properties of the underlying
	*** field if we are bound to a form property
	IF UPPER( lcAlias ) # 'THISFORM'
	  *** format the field if it is character
	  IF lcType = 'C'
	    .InputMask = REPLICATE( 'X', FSIZE( lcField, lcAlias ) )
	  ELSE
	    AFIELDS(laFields, lcAlias)
	    lnElement = ASCAN(laFields, UPPER(lcField))
	    IF lnElement > 0
	      lnRow = ASUBSCRIPT(laFields, lnElement, 1)
	      IF laFields[lnRow,2] = 'N'
		lcIntegerPart = REPLICATE('9', laFields[lnRow, 3] - laFields[lnRow, 4] - 1)
		lcDecimalPart = REPLICATE('9', laFields[lnRow, 4])
		.InputMask = lcIntegerPart + '.' + lcDecimalPart
	      ELSE	
		IF laFields[lnRow,2] = 'I'
		  *** Max integer value is 2147483647...make sure we don't overflow
		  .InputMask = '999,999,999'		
		ELSE
		  IF laFields[lnRow,2] = 'Y'			
		    *** Max currency value is 922337203685477.5807...make sure we don't overflow
		    .InputMask = '99,999,999,999,999.9999'	
		  ENDIF		&& IF laFields[lnRow,2] = 'Y'
		ENDIF		&& IF laFields[lnRow,2] = 'I'
	      ENDIF		&&	IF laFields[lnRow,2] = 'N'
	    ENDIF		&& IF lnElement > 0
	  ENDIF		&& 	IF lcType = 'C'
	ENDIF		&& 	IF UPPER( lcAlias ) # 'THISFORM'
      ENDIF		&&	IF INLIST( lcType, 'C', 'N', 'I', 'Y' )
    ENDIF		&& 	IF EMPTY( .InputMask )
  ENDIF		&& 	IF ! EMPTY( .ControlSource )
ENDWITH
Marcia
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform