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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 Text Entry 2

Status
Not open for further replies.

DaveJohnson

Technical User
Feb 13, 2005
13
0
0
GB
I have a form with several text boxes and controls, can I convert all keyboard inputs to uppercase as typed.

Thanks

Dave Johnson
 
Yes you can. Here's how:

Private Sub txtDesc_KeyPress(KeyAscii As Integer) ' convert keyed in data to uppercase
Dim KeyChar As String
KeyChar = Chr$(KeyAscii)
KeyChar = UCase(KeyChar)
KeyAscii = Asc(KeyChar)
End Sub

HTH

AMA
 
Thinking about it, please ingnore my last post as doing that has concequences for every application opened by the user. Them having to turn CAPSLOCK off everytime they wanted to switch apps would be incredibly frustrating.

Harleyquinn

---------------------------------
For tsunami relief donations
 
Probably better on the TextBox_Change subroutine..

Code:
   Private Sub txtDesc_Change()
      Dim intStart As Integer 
      intStart = txtDesc.SelStart 'Remember Cursor Position
      txtDesc.Text = UCase(txtDesc.Text) 'Change All To Upper
      txtDesc.SelStart = intStart 'Reset Cursor Position
   End Sub

Generally a Tidier Method.



jgjge3.gif
[tt]'Very funny, Scotty... Now Beam down my clothes.'[/tt]
 
This will be form wide by putting this in all forms
the upper/lower is controlled by one constant.

Set the form's KeyPreview property to true

------------------------------------------------
In a module
Global Const allow_lower_case As Boolean = False
or True to allow lower case

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

Private Sub Form_KeyPress(KeyAscii As Integer)

If allow_lower_case = False Then
KeyAscii = Asc(UCase$(Chr$(KeyAscii))) 'change
'all to upper case
End If


End Sub

I use this all the time works great

luck Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top