Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Annoyance] Correct Grammar
#12
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
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)