01-08-2009, 05:21 PM
Something less repetitive. Not sure if it's any faster. Also this function is made to be faster for words that need "An" because statements in an Else are always slower than statements in the actual If. I'm not sure which would come up more often (needing an An or just A), but to change it just add If Not FirstLetter and switched the statements around.
Code:
Private Function CheckGrammar(ByVal Word As String, Optional ByVal Caps As Byte = 0) As String
Dim FirstLetter As String * 1
FirstLetter = LCase$(Left$(Word, 1))
If FirstLetter = "$" Then
CheckGrammar = (Mid$(Word, 2, Len(Word) - 1))
Exit Function
End If
If FirstLetter Like "*[aeiou]*" Then
If Caps Then CheckGrammar = "An " Else CheckGrammar = "an "
Else
If Caps Then CheckGrammar = "A " Else CheckGrammar = "a "
End If
CheckGrammar = CheckGrammar & Word
End Function