0

我有一种情况,我试图在我的 vba 代码中使用 Erlang 计算器。我知道 Erlang 代码可以工作,因为我以前自己使用过它,但是当我将 erlang 代码复制/粘贴到另一个模块/在我的代码顶部时,我似乎无法调用我需要的函数。当我调用它时,Excel 没有响应并占用了大量内存。我知道这可能意味着某处存在无限循环,但我无法弄清楚它在哪里,或者这实际上是否是我不知道的另一个问题。

Erlang 计算器是一个免费程序,我很高兴感谢这个巧妙的计算。

我正在调用的函数:agentno()

    'Version 1.0 Joanne Sparkes, Expedio Virtual Assistance Ltd for Call Centre Helper
    '18th November 2008
    '---------------------------------------------------------------------------------

    Public Function utilisation(intensity As Double, agents As Long) As Double
    'Copyright Expedio Virtual Assistance Ltd 2008
    'calculates utilisation or agent occupancy
     On Error GoTo utilisationerror
        utilisation = intensity / agents

    utilisationexit:
        If utilisation < 0 Then utilisation = 0
        If utilisation > 1 Then utilisation = 1
    Exit Function

    utilisationerror:
        utilisation = 0
        Resume utilisationexit
    End Function

    Public Function top(intensity As Double, agents As Long) As Double
    'Copyright Expedio Virtual Assistance Ltd 2008
    'top row of Erlang-C Formula
        top = (intensity ^ agents) / Application.WorksheetFunction.Fact(agents)
    End Function

    Public Function erlangBR(intensity As Double, agents As Long) As Double
    'Copyright Expedio Virtual Assistance Ltd 2008
    'calculates summed factorial element of Erlang-C formula
    Dim k As Long, max As Long, answer As Double

    k = 0
    max = agents - 1
    answer = 0

    For k = 0 To max
    answer = answer + ((intensity ^ k) / Application.WorksheetFunction.Fact(k))
    Next k

    erlangBR = answer

    End Function

    Public Function ErlangC(intensity As Double, agents As Long) As Double
    'Copyright Expedio Virtual Assistance Ltd 2008
    'Brings together elements of Erlang C formula Top, Utilisation and ErlangBR
    On Error GoTo ErlangCError
    ErlangC = (top(intensity, agents)) / ((top(intensity, agents)) + ((1 -utilisation  (intensity, agents)) * erlangBR(intensity, agents)))

    ErlangCExit:
        If ErlangC < 0 Then ErlangC = 0
        If ErlangC > 1 Then ErlangC = 1
    Exit Function

    ErlangCError:
        Resume ErlangCExit

    End Function

    Public Function Servicelevel(intensity As Double, agents As Long, target As Double, duration As Double) As Double
    'Copyright Expedio Virtual Assistance Ltd 2008
    'calculation of service level
    On Error GoTo servicelevelerror

    Servicelevel = 1 - (ErlangC(intensity, agents) * Exp(-(agents - intensity) * target / duration))

    Servicelevelexit:
    If Servicelevel > 1 Then Servicelevel = 1
    If Servicelevel < 0 Then Servicelevel = 0
    Exit Function

    servicelevelerror:
        Servicelevel = 0
        Resume Servicelevelexit

    End Function

    Public Function agentno(intensity As Double, target As Double, duration As Double, servreq As Double) As Long
    'Copyright Expedio Virtual Assistance Ltd 2008
    'calculates minimum agent numbers for required service level
    Dim agents As Long, minagents As Long

    minagents = Int(intensity)
    agents = minagents

    While Servicelevel(intensity, agents, target, duration) < servreq
    agents = agents + 1
    Wend

    agentno = agents

    End Function

对长代码感到抱歉,但我觉得要真正弄清楚发生了什么,它需要它。

无论如何,我尝试调用 agentno() 函数(传递所需的东西),但我无法让它工作。

这是我尝试使用它的地方:

    For icount = 1 To 22
        For jcount = 1 To 6
            intensity = ((CallsForecasted(icount, jcount) / 1800) * duration) 'Calculates the intensity at each interval.
            AgentsNeeded(icount, jcount) = agentno(intensity, target, duration, servreq) '      <---         <---       <---          <---THIS IS THE ONE GIVING ME TROUBLE!!!!!!!!!!!!!!!!!!!!!!!!
        Next jcount
    Next icount

我已经完成了 debug.print 测试,发现强度计算正确(为了在此处发布,我将其删除),所以我知道到目前为止一切正常,但是一旦调用 agentno(),Excel 就会停止如上所述,响应并占用大量内存。数组 AgentsNeeded() 似乎很好,就像在我所有代码的开头声明的一样。

我错过了什么?

4

1 回答 1

0

我按照 GSerg 的建议进行了更多调试,这是导致问题的 servreq。我不知道它实际上将小数传递给了函数,所以当我弄清楚这一点时,这是让它工作的快速修复。

再次感谢 GSerg 鼓励像我这样的新手沿着正确的道路前进。:D

于 2013-02-24T03:10:23.597 回答