Wednesday, February 10, 2010

How do I add a case sensitive true false parameter to my function in Visual Basic?

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. And add a second button to the form that provides a case-insensitive count.








About Me


Member since: December 04, 2006


Total points: 109 (Level 1)


Points earned this week:


Total answers:


Best answers:





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 FunctionHow do I add a case sensitive true false parameter to my function in Visual Basic?
You could just have a boolean variable that is initialized to true. Then, only set it to false if the user chooses that option. However, you will always have to pass the boolean to the function, there is no way that can be avoided if you want to know its value inside the function. This should not be a problem if it is defaulted to true. Just pass the boolean to the function and use it like you would any other variable. No matter what, if you are using that value in the function, you need to pass it in.
  • virus removal
  • No comments:

    Post a Comment