SpecialCases.bas

 Attribute VB_Name = "SpecialCases"
Public Enum SpecialCaseConstants
    SentenceCase = 0
    ToggleCase = 1
End Enum

Public Function SpecialCase(sText As String, lCase As SpecialCaseConstants) As String
Dim Temp As String
Dim SChar As String
Dim CharNum As Integer
Dim Flag As Boolean
If lCase = SentenceCase Then ' If current special case is the 'sentence case'
                             ' selected by the user
   
    ' First, whole the text will be converted into lowercase
    sText = StrConv(sText, vbLowerCase)
 
    'Now parse the string to make sentence case
    For i = 1 To Len(sText)
        SChar = Mid$(sText, i, 1)
        CharNum = Asc(SChar)
 
        'First Letter of the sentence must be Capital in a standard sentence case
        If i = 1 And CharNum > 96 And CharNum < 123 Then
            CharNum = CharNum - 32
            Flag = True
        End If

        'Change to lowercase if there is no 'first char' in the sentence
        If Flag = False And CharNum > 64 And CharNum < 91 Then
            CharNum = CharNum + 32
        End If

        'Change to uppercase if there is a 'first char' in the sentence
        If Flag = True And CharNum > 96 And CharNum < 123 Then
            CharNum = CharNum - 32
            Flag = False
        End If
        Temp = Temp & Chr$(CharNum)

        'If character is period then next character will be capitalized
        If CharNum = 46 Then Flag = True
 
        'Only for first character Flag should always be false
        If i = 1 Then Flag = False
    Next i

    'Now returns the output to the function
    SpecialCase = Temp
   
Else ' If the user selected case is the tOGGLE cASE
   
    'Just reverses each character in the selected text i.e. sText
    For i = 1 To Len(sText)
        SChar = Mid$(sText, i, 1)
        CharNum = Asc(SChar)
        If CharNum > 96 And CharNum < 123 Then
            CharNum = CharNum - 32
        ElseIf CharNum > 64 And CharNum < 91 Then
            CharNum = CharNum + 32
        End If
        Temp = Temp & Chr$(CharNum)
    Next
    SpecialCase = Temp
End If
End Function

Project Homepage: