Reputation: 133
Is it possible to write an expression that will repeat some text over and over either for a specified number of repetitions or until it runs out of space in a textbox?
The text that needs to be displayed is coming from a field within a shared data set and can change depending on which database the user is connected to.
What I need to loop is
="~~"&First(Fields!SchemaText.Value,"Selection") &"~~"
What I would like as a output if possible is
~~Text~~~~Text~~~~Text~~~~Text~~~~Text~~
Basically is it possible to loop expressions in SSRS?
Upvotes: 0
Views: 1349
Reputation: 1
SSRS has a text function called StrDup. I don't know when the function was available or if the function has always been available.
Syntax: StrDup(integer, (char | object | string))
EX: =StrDup(3,"The end...") Output: The end...The end...The end...
EX: =StrDup(3, Chr(149)) & "Text" Output: •••Text
Look here: https://www.mssqltips.com/sqlservertip/4093/sql-server-reporting-services-string-manipulation/
Or just search the internet for "SSRS StrDup"
Upvotes: 0
Reputation: 10860
I don't see a way to wirite in an expression.
I think the easiest way would be to create a function in VB.
Function RepeatText(ByVal Text As String, ByVal Loops AS Integer) As String
Dim F AS Integer
RepeatText = ""
For F = 1 to Loops
RepeatText = RepeatText & "~~" & Text & "~~"
Next F
End Function
The your text box expression would be something like:
=CODE.RepeatText(Fields!SchemaText.Value, 4)
You'd want to replace the 4 with some code to determine the number of times you want the text to repeat or you can change the code so it figure out how many based on another field.
=CODE.RepeatText(Fields!SchemaText.Value, Fields!SOME_OTHER_FIELD.Value)
And then have the code figure it out:
Function RepeatText(ByVal Text As String, ByVal Type AS String) As String
Dim F AS Integer
Dim END AS Integer
If Type = "DB1" then END = 1
If Type = "DB2" then END = 2
If Type = "DB3" then END = 3
RepeatText = ""
For F = 1 to END
RepeatText = RepeatText & "~~" & Text & "~~"
Next F
End Function
Upvotes: 2
Reputation: 233
I'm not sure you can write it directly to an expression..
If I were you, I'd try to write a new 1 column dataset with the number of row you want containing the text value. Then, in the textbox expression, I'll try to get the result with a join().
I didn't test it, sorry, maybe I'm wrong.
Upvotes: 0