Microsoft KB Archive/138499

= How to Limit the Number of Characters Typed in a Combo Box =

Article ID: 138499

Article Last Modified on 2/11/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q138499



SUMMARY
You can limit the number of characters that a user can type into a text box by using the InputMask property. However, this property does not exist for a combo box. This article shows shows by example how to limit the number of characters typed in a combo box by placing code in the KeyPress event.



Step-by-Step Example
 Create a new form. On the Form menu, click New Property, and name the new property numb. Place a combo box on the form, and set its ControlSource, RowSourceType, and RowSource properties. Place at least one other control on the form.  Place the following code in the KeyPress event for the combo box to limit the number of characters entered into the combo box to 3: IF nKeyCode=13 OR nKeyCode=9  && test for ENTER or TAB THISFORM.numb=0             && and reset numb ELSE IF !(nkeyCode=127 OR ;      &&  BACKSPACE       nkeyCode=7 OR ;            &&  DELETE       nkeyCode=6 OR ;            &&  END key       nkeyCode=19 OR ;           &&  LEFT ARROW       nkeyCode=4 OR ;            &&  RIGHT ARROW       nkeyCode=1)                &&  HOME key THISFORM.numb=THISFORM.numb+1 && if not one of the above increment

IF THISFORM.numb=4      && When 4 characters have been entered THISFORM.numb=0       && reset numb to zero and flash a message ?? CHR(7)             && ring the bell =MESSAGEBOX("Enter only 3 characters") NODEFAULT             &&  do not enter the character typed. ENDIF ENDIF ENDIF 

Additional query words: VFoxWin mask format

Keywords: KB138499

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.