nmess88 - 1 year ago 74

Vb.net Question

I have a VB code that was used in Excel as macro. I want to use the same code in SSRS as a custom code but I get #Error as result. Here is the code

`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

And I have a text box in SSRS with expression

`=Code.ErlangC(65,60)`

When I run the report, the value in the text box is #Error.

Thank you.

Answer Source

Try changing the data type of `s`

variables from `Integer`

to `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
```

It is not tested but should work.

Let me know if this helps.