Wednesday, February 10, 2010

In Visual Basic how do I add a case sensitive true false parameter to my function?

I need to add a third parameter which is set to True if the search is case-sensitive and False if it isn鈥檛. The argument needs to be optional, defaulting to True, so that the existing call to the function doesn鈥檛 need to be modified.





Public Function WordCount(ByVal sInput, ByVal sSentence) As Integer


WordCount = 0





Dim i As Integer





For i = 1 To Len(sSentence)


Debug.Print(Mid(sSentence, i, Len(sInput)))


If Mid(sSentence, i, Len(sInput)) = sInput Then


WordCount = WordCount + 1


End If


Next i





End FunctionIn Visual Basic how do I add a case sensitive true false parameter to my function?
Public Function WordCount(ByVal sInput, ByVal sSentence, Optional bTrueFalse as Boolean = True) As Integer





If bTrueFalse = True Then


'Do true stuff


Else


'Do false stuff


End If








End Function

No comments:

Post a Comment