Tuesday, March 27, 2012

Embedded Code: whats the trick?

OK, I give up -- I can't get this to work. I am trying to put the following function into my report (RS 2005):

Public Shared Function ReportTotal(ByVal IsUnitCost As Boolean,ByVal TotalDirectCosts As Double, ByVal SalaryBenefitsTotal As Double, ByVal IndirectRate As Double, ByVal SS_Screened As Integer, ByVal UnitRate As Double) As Double
If IsUnitCost Then
Return SS_Screened * UnitRate
Else
Return TotalDirectCosts + SalaryBenefitsTotal * IndirectRate
End If
End Function

Supposedly, to use this code you put something like this for the expression in one of your fields: =Code.ReportTotal(...paramaters...)

However, when I type in "Code.", "ReportTotal" is not in the list provided by the Intellisense. If I type it in anyway, there is a red squiggly line under "ReportTotal", and then if I try to preview the report, I get an error: "The definition of report [report name] is invalid. Exception of type 'Microsoft.ReportingServices.ReportProcessing.ReportProcessingException' is thrown".

Real helpful. Does this mean there's an error in the Visual Basic? I tried to access the function improperly? What?

I tried with and without "Public", with and without "Shared". Same result.

Can anyone help??

I'm not familiar yet with 2005, but in 2000, there is a tab in the 'Report Properties' dialogue under the 'Report' menu.

If you put the code in there, IE:

Function FormatDateInterval(ByVal value As DateTime) As String
Return Year(value) & "-" & Month(value)
End Function

You can call the function by using something like:

= Code.FormatDateInterval(First(Fields!SaleDate.Value, "Foreclosures"))

Like I said, it works well in 2000. Hope it helps.

|||

Actually I found the answer. My code was fine -- it just doesn't get compiled until you deploy the report. I was testing it out in "preview" mode, and that's why it wasn't working.

Needless to say, this little feature is not documented anywhere!

sql

No comments:

Post a Comment