Receiving #Error when referencing CODE to a text box

  • Visual Studio "PREVIEW" of report which has a text box that calls CODE (see below) runs fine and renders my report perfectly. The CODE is called with this syntax:

    =code.GetProgram(Parameters!ProgramID)

    After deployment - I receive the #Error in the textbox containing the underlying CODE:

    _________________

    Function GetProgram(ByVal Program as Object) as String

    dim str

    dim i

    for i = 0 to Program.count - 1

    str = str & vbcrlf & Program.Label(i)

    Next

    Return str

    End Function

    _________________

    What am I doing wrong here?

    BT
  • What is the error that you are getting?

    What version of VB & Visual Studio? You also might try declaring the datatype of your variables and parameters.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • VS 2005 8.0.50727.762

    VB 2005 77626-009-00000007-41529

    We also added two references (on the Report Properties screen) System.Data and System.Data.SqlClient

    BT
  • Well, there's not a lot that I can tell without the erro Message, however, it's an odds-on bet that you are getting data-type errors. In particular, that whatever is coming through your [font="Courier New"]Program[/font] parameter is not a class that has the [font="Courier New"]Label[/font] property or not as a string array anyway.

    So I would add data-types and some error-handling that examines and reports on the actual object-type that you are receiving.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Thx for the reply. As mentioned, the only error I get is the displayed msg: "#Error" in the text box. AND, this report executes perfectly in mgmt studio. Is there a way to trap the error or look into a location housing this error?

    BT
  • Error-handling I can do, however, Error-Reporting I do not know how to do within Reporting Services.

    Here is your code rewritten with error-handling and standard WinForms error-reporting. You should have someone look at it and replace the [font="Courier New"]MsgBox()[/font] and [font="Courier New"]Err.Raise()[/font] calls as appropiate for Reporting Services:

    Function GetProgram(ByVal Program As Object) As String

    Dim str As String = ""

    Dim i As Integer

    If Program Is Nothing Then

    'replace this with error-reporting that will work in Reporting Services

    MsgBox("Program object is Nothing", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "GetProgram: Program object is bad")

    Err.Raise(vbObjectError + 1, "GetProgram", "Program object is nothing")

    ElseIf Program.GetType.ToString = i.GetType.ToString Then

    'replace this with error-reporting that will work in Reporting Services

    MsgBox("Program object is an Integer", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "GetProgram: Program object is bad")

    Err.Raise(vbObjectError + 1, "GetProgram", "Program object is an integer")

    End If

    Try

    For i = 0 To Program.count - 1

    str = str & vbCrLf & Program.Label(i)

    Next

    Catch ex As Exception

    'replace this with error-reporting that will work in Reporting Services

    MsgBox("Program object is " & Program.GetType.ToString, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "GetProgram: Program object is bad")

    Err.Raise(vbObjectError + 1, "GetProgram", "Program object is " & Program.GetType.ToString)

    End Try

    Return str

    End Function

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • I can't tell you what you're doing wrong. Looks okay to me, but maybe the problem is caused by a missing assembly on the server, because everything is working in VS. Looking at your code, I suggest to simply use the following expression instead of using VB:

    =Join(Parameters!ProgramID.Label, Chr(13) + Chr(10))

    Hope this helps!

    Peter

  • I don't see how this could work. You're passing in an ID (either character or integer) that identifies a program, and the function is expecting an object which IS the program. At very least - you either need to derive which "program" object you're dealing with within your function.

    Right now it's trying to get an count on a string value or an integer value, and it just doesn't understand what you're trying to tell it to do. To be honest - neither do I. You're missing something in there.

    Perhaps - all you need is some kind of cast operation to tell the function what kind of object you're passing it. Count() on the default object is also going to get it confused.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • I agree with you Matt, that's why the code changes that I posted report the actuall data-type of the Program parameter whenever anything goes wrong.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Gents - thx a million. I've forwarded this "active" discussion to my counterpart DBA and a developer. (I'm leaving for vacation - be back Friday). Both of your suggestions were discussed today. The folks will continue w/ this in the early a.m. Eastern Std time (USA)

    BT ~ DBA

    BT
  • I'd like to reiterate BT's gratefullness for the responses.

    The issue has been resolved via the following:

    Avoid Code, replace with... =Join(Parameters!ProgramID.Label, Chr(13) + Chr(10))

    Thanks Peter.

    Now unfortunately the root cause is disturbing as to why the original solution is not working when deployed.

    Please read the following article for a more detailed explanation, though it's not totally clear as to why

    it works from visual studio and not the deployed version.

    http://www.jameskovacs.com/blog/CommentView.aspx?guid=31eeaafd-a118-4e76-917d-78d54441aee9

    Our .NET developers will dig in and we'll post accordingly when we have more info.

    T'

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply