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
 
 
 
TitleConvert text into proper case
KeywordsTextBox, case, proper case, propercase, StrConv
CategoriesControls, Utilities
 
Visual Basic's StrConv function can capitalize the first letter in every word in a string, but it doesn't handle special values like "O'Conner" and "I.B.M" correctly. This program demonstrates StrConv and a custom ProperCase function.

The ProperCase function looks through the string seeing which characters are letters and which are not. It capitalizes the first letter after any non-letter.

 
' Convert the text into proper case.
Function ProperCase(ByVal txt As String) As String
Dim txtlen As Long
Dim need_cap As Boolean
Dim i As Integer
Dim ch As String

    txt = LCase(txt)
    txtlen = Len(txt)
    need_cap = True
    For i = 1 To txtlen
        ch = Mid$(txt, i, 1)
        If ch >= "a" And ch <= "z" Then
            If need_cap Then
                Mid$(txt, i, 1) = UCase$(ch)
                need_cap = False
            End If
        Else
            need_cap = True
        End If
    Next i
    ProperCase = txt
End Function
 
This function may not handle all special cases correctly but it does a better job than StrConv for this type of example.
 
 
Copyright © 1997-2001 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated