SSRS VB 自定义代码返回#Error

SSRS VB Custom Code returning #Error

我有一个 VB 代码在 Excel 中用作宏。我想在 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。

谢谢。

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

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

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

尝试将 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

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

如果有帮助请告诉我。