SSRS VB自定义代码返回#Error

时间:2016-07-27 19:50:26

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

我有一个在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。

谢谢。

2 个答案:

答案 0 :(得分: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

没有经过测试但应该有效。

如果有帮助,请告诉我。

答案 1 :(得分:0)

如果在带有SSDT的Visual Studio中运行此操作,则可以在“错误列表”窗格中看到错误的文本。在这种情况下,错误是:

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

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