VB and VBA Users Source Code: Forcing a textbox to be either lower or upper case
[
Home
|
Contents
|
Search
|
Reply
| Previous |
Next
]
VB/VBA Source Code
Forcing a textbox to be either lower or upper case
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Wednesday, October 10, 2001
Hits:
1092
Category:
Windows Forms/GUI/Controls/Graphics
Article:
The following is a function forces a textbox into either upper of lower case by altering the KeyAscii received during the KeyPress event. 'Purpose : Forces a textbox into upper or lower case. 'Inputs : KeyAscii The ascii value of the character (as received by the _KeyPress event) ' UpperCase If True forces the textbox into upper case, else lower case. 'Outputs : Returns the new ASCII value 'Author : Andrew Baker 'Date : 25/04/2001 'Notes : Assumes an English ASCII character set 'Example : 'Private Sub Text1_KeyPress(KeyAscii As Integer) ' KeyAscii = TextboxForceCase(KeyAscii, True) 'Force the textbox into upper case 'End Sub Function TextboxForceCase(KeyAscii As Integer, UpperCase As Boolean) As Integer TextboxForceCase = KeyAscii If UpperCase Then 'Force characters into upper case If KeyAscii > 96 And KeyAscii < 123 Then 'Typed letter from "a-z", map it to "A-Z" TextboxForceCase = KeyAscii - 32 End If Else 'Force into lower case If KeyAscii > 64 And KeyAscii < 91 Then 'Typed letter from "A-Z", map it to "a-z" TextboxForceCase = KeyAscii + 32 End If End If End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder