Microsoft KB Archive/148918

= How to Capitalize Some Characters in a Text Box Automatically =

Article ID: 148918

Article Last Modified on 9/30/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition

-



This article was previously published under Q148918



SUMMARY
When typing names into a text box, you can have the first letter of each word automatically capitalized. This can be done in the KeyPress event by checking each character that is typed and capitalizing it if it is the first character entered or if the character before it is blank. Names such as "Van Camp" would have the first letter of each part of the name automatically capitalized. However, names like "MacDonald" would still require that you manually capitalize the D key.



Step-by-Step Procedure
The following steps illustrate how to use the KeyPress event to check each character and enforce the rule that the first character of each word be capitalized.

 Create a new form, and place a text box on it. Create a new property for the form. On the Form menu, click New Property, and in the Name box, type Lastchar. Click OK, and return to the form.  In the When Event of the text box, place the following code: THISFORM.lastchar = 32 This assigns the numeric value of a space (32) to the lastchar variable.   In the KeyPress event of the text box, place the following code: IF THISFORM.lastchar = 32  && Checks lastchar to see if it is                               && equal the numeric value of a space. NODEFAULT              && Doesn't allow the character to be                               && entered because it is lowercase. KEYBOARD UPPER(CHR(nKeyCode)) && Places the character into the && text box in uppercase. ENDIF IF nKeyCode=127 AND LEN(ALLTRIM(this.value))=1 &&  Checks to see if                                   && the user has backspaced over && the first letter in the text box. THISFORM.lastchar=32       && Assigns numeric value of a space && to lastchar. ELSE THISFORM.lastchar= nKeyCode && Assigns last keystroke to Lastchar ENDIF  Run the form, and type the following into the text box:

van camp

Note that the V and C are automatically capitalized. Backspace over the whole name, and start typing another name. Note that the first character is automatically capitalized as a new name is typed.</ol>

Additional query words: VFoxWin

Keywords: kbcode KB148918

-

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

© Microsoft Corporation. All rights reserved.