Search code examples
reporting-servicessplitexpressionssrs-2012ssrs-tablix

SSRS Split expression #Error


Trying to get this expression working:

IIF(Fields!Text.Value like "*som:*",Split(Fields!Text.Value, ": ").GetValue(0)&":" & vbcrlf & Split(Fields!Text.Value, ": ").GetValue(1), Fields!Text.Value)

And for the fields which contain "som:" it works as I want but not for the "else fields" which show #Error. I've also tried Fields!Text.Value.ToString().Contain("som:") but got the same result.

The Warning goes: The Value expression for the textrun ‘XXXXXX.Paragraphs[0].TextRuns[0]’ contains an error: Index out of matrix/range (trying translate it so sorry if the error message is not exact)

The expression is made on a textbox and I need to have this function cause our costumer requires it.

I want this input kinda:

TExt text text som:

text text text

and else

TExt text text text text text

What am I doing wrong?


Solution

  • Please use custom code:

    Report ► Report properties ► Code (Report is on the toolbar on the TOP)

    Add below code:

    Function Valid(ByVal str As String) As String
        If (str.Contains("tom:")) Then
            Return str.Split(":").GetValue(0) + ":" + vbCrLf + str.Split(":").GetValue(1)
        Else
            Return str
        End If
    End Function
    

    user like this: "=Code.Valid(Fields!Text.Value)"