Public Function GetSort() As String
Select Case Report.Parameters!SortBy.Value
Case "GM"
Return CStr(Fields!GM.Value)
Case "STYLECODE"
Return Fields!STYLECODE.Value
Case "CUSTOMER"
Return Fields!CUSTOMER.Value
End Select
End Function
I have a call to Code.GetSort() in the sorting tab of the report data table.
I get this error when I build:
Error 1 [rsCompilerErrorInCode] There is an error on line 4 of custom code: [BC30469] Reference to a non-shared member requires an object reference.
i think the problem is in the code body can't use report parameters.
so the code maybe is:
public Function GetSort(SortType as String) As String
Select Case SortType
then use it like GetSort(Report.Parameters!SortBy.Value) in the expression.
|||
Just pass the paremeter value to the function in the code and use that inside your code like this
Public Function GetSort(SortBy as String) As String
Select Case SortBy
........
End Function
Shyam
|||Hi Sam,
You have to use GetSort= instead of Return (VB not accepts return keyword)
Public Function GetSort() As String
Select Case Report.Parameters!SortBy.Value
Case "GM"
GetSort=CStr(Fields!GM.Value)
Case "STYLECODE"
GetSort= Fields!STYLECODE.Value
Case "CUSTOMER"
GetSort= Fields!CUSTOMER.Value
End Select
End Function
Regards,
Nanda kumar R
|||Mr Nanda Kumar,
Please get your basics right. You can use Return keyword in the code in report.
The error is because Parameter is being referenced in the code the way it is referenced in expressions.
Shyam
|||Looks like we all need to get our basics right.
Problem was not that the parameter was referenced in the body, but that fields were referenced in the header. So now I have this in Report->Properties ->Code:
Public Function GetSort(sortby As String, sc As String, cu As String) As String
Select Case sortby
Case "STYLECODE"
Return sc
Case "CUSTOMER"
Return cu
End Select
End Function
And this in the sort tab of the data table properties:
=IIF(Parameters!SortBy.Value="GM",
Fields!GM.Value,
Code.GetSort(Parameters!SortBy.Value,Fields!STYLECODE.Value,Fields!CUSTOMER.Value))
I really wanted to avoid a mind bending iif statement hence the desire for the select case statement in the code. The GM field is numeric and it does not sort as a string so I have to handle that one separately.
|||I have another question if you all will so indulge me: In Visual Studio Report Designer, Click File-> New -> New File -> VBScript File.
If I create a code file this way, how do I call a function in it from the report?
Thanks
|||
Dont you get the same error when you use Parameters!something.Value in code?
It will give that error!!!!!!
You can only add reference to .dll assemblies and use the methods in those assemblies.
Shyam
|||>>You can only add reference to .dll assemblies and use the methods in those assemblies.Sorry for asking silly questions but what is the purpose of the vbscript file capability if you cant call functions in your script?
|||
For SSRS, the referenced code should be pre-compiled but vbscript can only be compiled to an exe or interpreted at runtime.
You can transform your vbscript code to .net code and place it under code section directly.
Can u please mark the previous issue as marked?
Shyam
No comments:
Post a Comment