March 12, 2016 at 4:45 am
Hi All,
I have a report variable that has a value I would like to reference in my custom code but can't work out the syntax... or is it even possible.
For instance using the following function code I got from here for alternating row colours, I would like the value of the colours to come from a report variable. The reason for that is I want the source of the value to ultimately be a table. I can populate the variable ok it is using it in code that I am having trouble. If this is not possible my work around would be to pass the variable value in to code but would hope to avoid that.
Function AlternateColor(Byval rowNumber as integer) As String
Dim OddColor As String =Variables!RowBackColorOdd.Value
Dim EvenColor As String =Variables!RowBackColorEven.Value
If rowNumber mod 2 = 0 then
Return EvenColor
Else
Return OddColor
End If
End Function
Thanks
Steve
May 30, 2016 at 4:54 am
Hi Steve,
You can use it like this,
Function AlternateColor(Byval rowNumber as integer,EvenColor as string,OddColor as string) As String
If rowNumber mod 2 = 0 then
Return EvenColor
Else
Return OddColor
End If
End Function
Now you can pass the value of each of the variables to EvenColor and OddColor during the function call, i.e. instead of passing only the row number to the function you will also have to pass the variables value for the Even and Odd Color respectively. something like,
=Code.AlternateColur(RowNumber(YourDataset),Variables!RowBackColorEven.Value,Variables!RowBackColorOdd.Value)
Hope this works for you !
Thanks,
Ansuman
May 30, 2016 at 5:06 am
Hi Ansuman,
Thanks for the reply... actually that is what I am currently doing and I should have said that, my bad.
My general philosophy when writing code is to make the 'call' as simple as possible, minimal parms, and have most of the decision logic in the code. In the current call the call is actually making the decision on what colour to use, in a sense.
Thanks
Steve
May 30, 2016 at 6:07 am
Hi Steve,
That's nice that you have found the solution already. Unfortunately variables cannot be passed in the manner you have been trying earlier. This is the easiest way, there is one more option by using the ReportItems object which is littler tricky. Since your result is already achieved I am not discussing that now.
Thanks,
Ansuman
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply