Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Turning Text to CAPS 3

Status
Not open for further replies.

JaeBrett

Programmer
May 5, 2003
196
CN
On KeyPress, how can turn a character to a capital letter ... if, in the event that it IS a letter.


Thanks
 
Try,

Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
'// Capitalize the entered small letters.
   If KeyAscii > 96 And KeyAscii < 123 Then KeyAscii = KeyAscii - 32
End Sub

Thanks and Good Luck!

zemp
 
I would use the UCase command. It can be used like such:

Chr(KeyAscii)=UCase(Chr(KeyAscii))
 
Consider using the UCase command but i would watch out for how you are using the data. For example if the user pastes the data into the text box using the mouse your keypress event will not fire. Before you use the data it may be best to implement it there. i.e.
Code:
MyString = Ucase(Text1.Text)




----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 

1. Use UCase$() as Golom suggested instead of UCase().

2. Place it in the edit control's Change event instead

3. Use a flag if you want to keep the Change event from firing a second uneeded time.
 
JaeBrett,

hello..
u may try this code.

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii Then
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub

jayrojz
 


jayrojz, Already suggested, but an additional problem which you will find with this is when the user copies and pastes text into the edit control...
 
Hi All,

Would not be easier to utilise Golom's change method, but Text1_Change routine instead, this way it catches everything, no?

Private Sub Text1_Change()
Dim iCurPos As Integer

'Set Current Position
iCurPos = Text1.SelStart
Text1.Text = UCase$(Text1.Text)
'Return Cursor to Current Position
Text1.SelStart = iCurPos
End Sub

Hope this Helps,



jgjge3.gif


[tt]&quot;Do not put off until tomorrow what you cannot put off until the day after tomorrow just as well.&quot; - Mark Twain[/tt]
 

er, that's what I wrote...

If you step through this, you will notice that the Change event fires a second time and all the code is executed again.
You cannot prevent the event from firing again, but can keep the code from executing again using the mentioned flag:

Private Sub Text1_Change()
Static bGetOut As Boolean
If bGetOut Then Exit Sub
bGetOut = True
.
.
.
.
bGetOut = False
End Sub
 
I could give stars to everyone for all the help. I put it in the Change and used a static boolean to prevent the code from executing twice.
 
CClint> Sorry buddy, didn't read the post properly, and also didn't realise that the code executes twice, although if it thought about it logically.... lol

A Star for you for the Getout Clause, I just wish i had a &quot;Static bGetOut as Boolean&quot; when i got married!
:)



jgjge3.gif


[tt]&quot;Do not put off until tomorrow what you cannot put off until the day after tomorrow just as well.&quot; - Mark Twain[/tt]
 
he he he,,

i did not read the remarks of &quot;ca8msm&quot;.. thanks for the info.. ill use it in change event and apply static boolean from now on for that prob also..
long way to go..:-(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top