Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleMake a TextBox automatically capitalize input using the API
Keywordsuppercase, upper case, capitalize, TextBox, input
CategoriesControls, API
 
Use the SetWindowLong API function to make the TextBox automatically convert text into upper case.
 
' Make the TextBox convert input to UPPERCASE.
Private Sub SetAllCaps(ByVal txt As TextBox)
Const GWL_STYLE = (-16)
Const ES_UPPERCASE = &H8&

Dim style As Long

    style = GetWindowLong(txt.hwnd, GWL_STYLE)
    style = style Or ES_UPPERCASE
    SetWindowLong txt.hwnd, GWL_STYLE, style
End Sub
 
This method has a couple of advantages. First, it is handled at a lower level than the VB event handler so it is more efficient. That's not a huge deal since usually it's a user entering text so it's going to be fast enough either way.

Second, it's "set and forget." Once you set the flag, you don't need to have the VB code cluttering things up. You don't need to write separate event handlers for each TextBox.

 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated