VB Function gives error in RDLC <Code> Element RRS feed

  • Question

  • Hello,
    I'm trying to use a VB function in an RDLC file. The function works fine in a *.vb file, but when I move it to RDLC I get the following error
    • An error occurred during local report processing.
      • The definition of the report 'Main Report' is invalid.
        • An unexpected error occurred while compiling expressions. Native compiler return value: ‘[BC42105] Function 'pageNumber' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.’.

    The function in the RDLC is
    Function pageNumber(ByVal currentPage As Integer)
    Dim groupTotal As Integer = 7
    Dim modPage As Integer
    Dim test As Integer = Math.DivRem(currentPage, groupTotal, modPage)
    If modPage = 0 Then pageNumber = groupTotal Else pageNumber = modPage
    End Function

    I've tried reducing the function to nothing but a single line that returns a constant value and I get the same error. I've also tried terminating the function with "return x" and with "Exit Function" after setting a the function name to a value.

    I originally had "As Integer" on the end of the function header, but the RDLC engine said it expected an end of line, so I took it out.

    I'm a C# programmer and this is my first foray into VB, I may be missing something quite obvious.

    I'm using the WebForms version of ReportViewer.

    Thank you for any help you can offer.
    Tony Barton.

    Wednesday, July 4, 2007 2:20 AM


  • I found the solution and thought there may be others having a similar problem.
    The error given by ReportViewer doesn't have much to do with the cause of the problem.

    My RDLC code is written on the fly by a C# web app that uses an RDLC API that I wrote, so the VB is inserted in the code as the result of a StringBuilder.ToString call.  I guess because VB doesn't use a char to tell the compiler when a line has ended (e.g. ';'), the individual lines have to actually be on individual lines.

    I added "\r\n" to the end of each VB string I appended to the StringBuilder and the function works perfectly.

    Lesson:  If feeding VB to a report at runtime, you have to use "\r\n" at the end of each VB statement contained in the feeding string.  Otherwise you may spend hours wondering why the &*^$ it doesn't work.

    Many thanks to those who looked at my post and spent time wondering about the cause.
    Wednesday, July 4, 2007 7:32 PM