Click to See Complete Forum and Search --> : Converting characters to upper-case...


YourSurrogateGod
July 18th, 2005, 10:01 PM
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) _
Handles TextBox1.KeyPress
' replace the selected text with an uppercase character. (Inserts at caret position
' if no text is selected.)
If TextBox1.Text.Length < TextBox1.MaxLength Then
TextBox1.SelectedText = e.KeyChar.ToString.ToUpper
End If
' cancel standard processing.
e.Handled = True
End Sub
Ok, here's the problem. What I'm trying to do is have a small text box that will accept characters and automatically turn them into capital letters. However, when I try to erase characters using the back-space key, that doesn't work at all. What seems to be the problem?

adcomp
July 18th, 2005, 11:12 PM
Hi;

Use LostFocus instead

text1.text = ucase(text1.text)

Shuja Ali
July 19th, 2005, 01:04 AM
This code should help you in trapping the backspace..

'If keypressed is Backspace, don't do nothing
If e.KeyChar = vbBack Then
Exit Sub
End If

sanjay13
July 19th, 2005, 07:27 AM
if your only requirement is uppercassing of all characters entered then try setting the 'CharacterCasing' property of the textbox to 'Upper'.

YourSurrogateGod
July 19th, 2005, 07:33 AM
Hi;

Use LostFocus instead

text1.text = ucase(text1.text)
That prevents me from inputting anything at all...

YourSurrogateGod
July 19th, 2005, 07:34 AM
if your only requirement is uppercassing of all characters entered then try setting the 'CharacterCasing' property of the textbox to 'Upper'.
Geez, I can't believe I missed that. Thanks :) .