Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleConvert the text the user is typing in a TextBox to Proper Case
DescriptionThis example shows how to convert the text the user is typing in a TextBox to Proper Case in Visual Basic 6.
KeywordsTextBox, convert, proper case, StrConv
CategoriesControls, Miscellany, Strings
 
This example has three TextBoxes that convert their text into UPPER CASE, lower case, and Proper Case. Each control's Change event handler works in the same way. It stores the TextBox's SelStart and SelLength properties in local variables, converts the text as necessary, and restores the SelStart and SelLength values.

The routines use StrConv to convert the text to UPPER CASE, lower case, or Proper Case.

 
Private Sub txtLowerCase_Change()
Dim sel_start As Integer
Dim sel_length As Integer

    sel_start = txtLowerCase.SelStart
    sel_length = txtLowerCase.SelLength
    txtLowerCase.Text = StrConv(txtLowerCase.Text, _
        vbLowerCase)
    txtLowerCase.SelStart = sel_start
    txtLowerCase.SelLength = sel_length
End Sub

Private Sub txtProperCase_Change()
Dim sel_start As Integer
Dim sel_length As Integer

    sel_start = txtProperCase.SelStart
    sel_length = txtProperCase.SelLength
    txtProperCase.Text = StrConv(txtProperCase.Text, _
        vbProperCase)
    txtProperCase.SelStart = sel_start
    txtProperCase.SelLength = sel_length
End Sub

Private Sub txtUpperCase_Change()
Dim sel_start As Integer
Dim sel_length As Integer

    sel_start = txtUpperCase.SelStart
    sel_length = txtUpperCase.SelLength
    txtUpperCase.Text = StrConv(txtUpperCase.Text, _
        vbUpperCase)
    txtUpperCase.SelStart = sel_start
    txtUpperCase.SelLength = sel_length
End Sub
 
Note that you can set extended styles in a TextBox to make it produce UPPER CASE or lower case, or to allow only digits. In that case, the Change event handler isn't necessary, although it provide more flexibility (for example, you can implement Proper Case). See:

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