【问题标题】:SSRS VB Custom Code returning #ErrorSSRS VB 自定义代码返回 #Error
【发布时间】:2016-07-27 19:50:26
【问题描述】:

我有一个在 Excel 中用作宏的 VB 代码。我想在 SSRS 中使用相同的代码作为自定义代码,但结果是 #Error。这是代码

Public Function ErlangC(ByVal m As Integer, ByVal u As Double) As Double
    Dim d as Double
    Dim s as Integer
    Dim k as Integer

    d = PowerFact(m, u)
    s = 1
    For k = 1 To m - 1
        s = s + PowerFact(k, u)
    Next k
    ErlangC = d / (d + (1 - u / m) * s)
End Function

Public Function PowerFact(ByVal m As Integer, ByVal x As Double) As Double
    Dim s as Integer
    Dim k as Integer

    s = 0
    For k = 1 To m
        s = s + Math.Log(x / k)
    Next k
    PowerFact = Math.Exp(s)
End Function

我在 SSRS 中有一个带有表达式的文本框

=Code.ErlangC(65,60)

当我运行报告时,文本框中的值为#Error。

谢谢。

【问题讨论】:

    标签: vb.net reporting-services ssrs-2008-r2


    【解决方案1】:

    尝试将s变量的数据类型从Integer更改为Double

    Public Function ErlangC(ByVal m As Integer, ByVal u As Double) As Double
        Dim d as Double
        Dim s as Double
        Dim k as Integer
    
        d = PowerFact(m, u)
        s = 1
        For k = 1 To m - 1
            s = s + PowerFact(k, u)
        Next k
        ErlangC = d / (d + (1 - u / m) * s)
    End Function
    
    Public Function PowerFact(ByVal m As Integer, ByVal x As Double) As Double
        Dim s as Double
        Dim k as Integer
    
        s = 0
        For k = 1 To m
            s = s + System.Math.Log(x / k)
        Next k
    
        PowerFact = System.Math.Exp(s)
    End Function
    

    它没有经过测试,但应该可以工作。

    如果这有帮助,请告诉我。

    【讨论】:

    • 就是这样!将 Integer 更改为 Double 有帮助。
    【解决方案2】:

    如果您在 Visual Studio 中使用 SSDT 运行此程序,您可以在错误列表窗格中看到错误文本。在这种情况下,错误是:

    警告 1 [rsRuntimeErrorInExpression] 文本运行“Textbox1.Paragraphs[0].TextRuns[0]”的值表达式包含错误:算术运算导致溢出。 \asufsp20\Homes$\spwhite1.ASURITE\Documents\Visual Studio 2013\projects\Report Project1\Report Project1\Report1.rdl 0 0

    所以这是一个数学问题。我尝试了使用其他值的函数并且它有效,但它可能没有返回预期的答案。

    【讨论】:

    • 你说得对,这是一个数学问题。该功能适用​​于较小的数字。亚历杭德罗的回答对我有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-09
    • 1970-01-01
    相关资源
    最近更新 更多