Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 24,407 times

Related Categories

Proper Case Function

hobbes68

This neat function capitalizes the first characters of each word setting, and turns all other characters to lowercase.

Public Function ProperCase(strText As String) As String 'Capitalize all first characters of the input string 'and set all the others to lowercase
    On Error GoTo Err_ProperCase
   
    Dim I As Integer, intLen As Integer, strTemp As String, strFinal As String
    Dim isSpace As Boolean
    strTemp = LCase(Trim(strText))
    intLen = Len(Trim(strText))
    strFinal = String(intLen, " ")
    isSpace = True
    For I = 1 To intLen
        If Mid(strTemp, I, 1) = Chr(32) Then
            strFinal = Mid(strFinal, 1, I - 1) & Chr(32) & Mid(strFinal, I + 1)
            isSpace = True
        ElseIf isSpace Then
            strFinal = Mid(strFinal, 1, I - 1) & UCase(Mid(strTemp, I, 1)) & Mid(strFinal, I + 1)
            isSpace = False
        Else
            strFinal = Mid(strFinal, 1, I - 1) & Mid(strTemp, I, 1) & Mid(strFinal, I + 1)
        End If
    Next I
    ProperCase = strFinal
   
Exit_ProperCase:
    Exit Function
   
Err_ProperCase:
    MsgBox Err.Description & vbCrLf & strText, vbInformation, "ProperCase function"
End Function

Comments