Thursday, April 5, 2012

SSRS - ShowParameterValues

If you've ever wanted to display the parameters selected by an SSRS report user right on the report this function may help .


Public Shared Function ShowParameterValues(ByVal strParmLabel as String, ByVal parameter as Parameter, PrefixCRLF as integer, Optional ByVal intLabelChars as integer = nothing) as String

On Error Goto ProcError

Dim s as String
Dim spadchar as String

spadchar = " "

If IsNothing(intLabelChars) then
   intLabelChars = 20
End If

If parameter.IsMultiValue then
  s = ""
  For i as integer = 0 to parameter.Count-1
    s = s + CStr(parameter.label(i)) + " "
  Next
Else
  s = CStr(parameter.Value)
End If

If Not String.IsNullOrEmpty(s)
   If intLabelChars >= strParmLabel.length then
      s = strParmLabel + spadchar.PadRight(intLabelChars - strParmLabel.length, spadchar) + ":" + s
   else
      s = strParmLabel + ":" + s + " "
   End If
   s = "[" + s.trim() + "]"
   If PrefixCRLF = 1
      s = CHR(13) + CHR(10) + s
   End if
End If

Return s

ProcError:

   Return err.description

End Function

No comments:

Post a Comment