Monday, May 9, 2011

SSRS: Function ExistsInArray (Custom Report Builder Code)

A simple function for embedding in SSRS Reports that allows you to check and see if an item exists in a array of items (in either a case sensitive or insensitive way).


Here is the function;

Function ExistsInArray(ByVal SearchTerm As String, ByVal MultiValueParam As Parameter, optional ByVal CaseInsensitive as Boolean = False) As Boolean
  For i As Integer = 0 To MultiValueParam.Count - 1
    If CaseInsensitive = True Then
     If CStr(LCase(MultiValueParam.Value(i))) = LCase(SearchTerm) Then Return True
      Else
        If CStr(MultiValueParam.Value(i)) = SearchTerm Then Return True
      End If
  Next
  Return False
End Function

You pass in the SearchTerm as a string and then the multi-value parameter you wish to search through. Optionally you can make the search case insensitive by specifying True for the third parameter. The function loops through the items and when it finds one that matches it returns True, otherwise if it finds nothing it returns False.
Post a Comment