Parameter error in custom code, report builder 3
Hi, I am new to report builder. I need to get the parameter value in the custom code to do some calculations. The parameter is defined as report parameter manually. I have no problem to read it from the report expression. But when I try to read it in custom code, I got following error: "Failed to load expression host assembly. Details: The expression that references the parameter 'TotalSectorActiveMoneyMonth1' does not exist in the Parameters collection. Letters in the names of parameters must use the correct case. (rsErrorLoadingExprHostAssembly)" The parameter exists and the spelling is correct. Here is the code I called in Custom Code which throws the above error: Dim t as double = GetParameterValues(Report.Parameters!TotalSectorActiveMoneyMonth1) It works well while I call the parameter from report expression: =code.GetParameterValues(Parameters!TotalSectorActiveMoneyMonth1) Have anyone experienced the similar problem? Any idea how I can make it work in custom code? I will highly appreciate any suggetion or work around. Thanks, Jenny
July 6th, 2012 4:01pm

Hi There Thanks for your posting. You have to create a function in custom code, I could not see any function definition So please create a function like Public Function ShowParameterValues(ByVal parameter as Parameter) Your logic come here End Function and then you can call like this =Code.ShowParameterValues(Parameters!Test) Many thanks Syed Qazafi Anjum
Free Windows Admin Tool Kit Click here and download it now
July 6th, 2012 9:53pm

Hi Syed, Thanks for your answer. I do have an function defined as following. It returns the sum of the multiple values of the parameter. I can call it as you descirbed as the report expression and it works. But I need to call it in the custom code to do more calcuation before return to the report. Do you know why it throws error when I call it in custom code like this? The parameter exists. ... Public Function GetParameterValues(ByVal parameter as Parameter) as Double Dim s as Double = 0 If parameter.IsMultiValue then For i as integer = 0 to parameter.Count-1 s = s + parameter.Value(i) Next End If Return s End Function I am really stuck here. I searched online and can't find any answer. Please help! Jenny Dim t as double = GetParameterValues(Report.Parameters!TotalSectorActiveMoneyMonth1)
July 9th, 2012 11:19pm

Hi There<o:p></o:p> Thanks for your posting. Can you please give some more details when you got the error, what is the expression and where do you put that expression when you get this error.<o:p></o:p> In your code I can see that you are getting the um of your multivalued parameter, would you be like to do more calculation on that sum<o:p></o:p> Please give some more details that I might be able to help you out<o:p></o:p> Many thanks<o:p></o:p> Syed <o:p></o:p> Dim public totalBalance as Integer Public Function GetParameterValues(ByVal parameter as Parameter) as Double Dim s as Double = 0 If parameter.IsMultiValue then For i as integer = 0 to parameter.Count-1 s = s + parameter.Value(i) Next End If totalBalance =s Return s End Function Public Function GetTotal() return totalBalance End Function =code.GetTotal()
Free Windows Admin Tool Kit Click here and download it now
July 9th, 2012 11:31pm

Hi Syed, Thanks so much for looking into it for me. I really appreciate your time and expertise. I tried to call the parameter in the custom code as following: Dim t as double = GetParameterValues(Report.Parameters!TotalSectorActiveMoneyMonth1) The parameter 'TotalSectorActiveMoneyMonth1' is defined manually as report parameter. But I got the following error: "Failed to load expression host assembly. Details: The expression that references the parameter 'TotalSectorActiveMoneyMonth1' does not exist in the Parameters collection. Letters in the names of parameters must use the correct case. (rsErrorLoadingExprHostAssembly)" This only happen when the parameter is called from custome code. It worked well if the parameter is called in the report expression directly like : =code.GetParameterValues(Parameters!TotalSectorActiveMoneyMonth1) Any idea? I am scratching my head now. Jenny
July 10th, 2012 10:33am

Jenny, just a thought. did you put like value at the end of that param, like so, and see what happen: Dim t as double = GetParameterValues(Report.Parameters!TotalSectorActiveMoneyMonth1.Value) and same thing when calling them: =code.GetParameterValues(Parameters!TotalSectorActiveMoneyMonth1.Value) good luck. Think out of the box
Free Windows Admin Tool Kit Click here and download it now
July 10th, 2012 11:16am

Thanks for the reply. I tried to add .Value before. It gives the same error. :( Jenny
July 10th, 2012 11:51am

I found a workaround to avoid calling parameter in custome code. Still curious to know why it doesn't work though. Thanks everyone for the replies. Jenny
Free Windows Admin Tool Kit Click here and download it now
July 12th, 2012 3:31pm

Hi There Thanks for your posting.I think you are doing in slightly wrong way. Please try this one Create Function like this Dim public totalBalance as Integer Public Function GetParameterValues(ByVal parameter as Parameter) as Double Dim s as Double = 0 If parameter.IsMultiValue then For i as integer = 0 to parameter.Count-1 s = s + parameter.Value(i) Next End If totalBalance =s Return s End Function Public Function GetTotal() return totalBalance End Function Dim public totalBalance as Integer Public Function GetParameterValues(ByVal parameter as Parameter) as Double Dim s as Double = 0 If parameter.IsMultiValue then For i as integer = 0 to parameter.Count-1 s = s + parameter.Value(i) Next End If totalBalance =s Return s End Function Public Function GetTotal() return totalBalance End Function Now your public variable total Balance got all the values of your parameters. You can use that variable for some other calculation For example if you want to use parameter values in any other function you can use Code.totalBalance or you can use =code.GetTotal() And it will give you all the values I hope you will understand now Many thanks Syed Qazafi Anjum
July 12th, 2012 5:00pm

Hi There Thanks for your posting.I think you are doing in slightly wrong way. Please try this one Create Function like this Dim public totalBalance as Integer Public Function GetParameterValues(ByVal parameter as Parameter) as Double Dim s as Double = 0 If parameter.IsMultiValue then For i as integer = 0 to parameter.Count-1 s = s + parameter.Value(i) Next End If totalBalance =s Return s End Function Public Function GetTotal() return totalBalance End Function Dim public totalBalance as Integer Public Function GetParameterValues(ByVal parameter as Parameter) as Double Dim s as Double = 0 If parameter.IsMultiValue then For i as integer = 0 to parameter.Count-1 s = s + parameter.Value(i) Next End If totalBalance =s Return s End Function Public Function GetTotal() return totalBalance End Function Now your public variable total Balance got all the values of your parameters. You can use that variable for some other calculation For example if you want to use parameter values in any other function you can use Code.totalBalance or you can use =code.GetTotal() And it will give you all the values I hope you will understand now Many thanks Syed Qazafi Anjum
Free Windows Admin Tool Kit Click here and download it now
July 12th, 2012 5:02pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics