Hello All,

Could you please help me with the following VBA code that I have to understand (but I am not aware of VBA)

``Public Function ErlangB(Servers As Single, Intensity As Single) As Single 'The Erlang B formula calculates the percentage likelyhood of the call ' being blocked, that is that all the trunks are in use and the caller ' will receive a busy signal. ' Servers = Number of telephone lines ' Intensity = Arrival rate of calls / Completion rate of calls '   Arrival rate = the number of calls arriving per hour '   Completion rate = the number of calls completed per hour Dim Val As Single, Last As Single, B As Single Dim Count As Long, MaxIterate As Long On Error GoTo ErlangBError      If (Servers < 0) Or (Intensity < 0) Then           ErlangB = 0           Exit Function      End If      MaxIterate = Fix(Servers)      Val = Intensity      Last = 1 ' for server = 0      For Count = 1 To MaxIterate           B = (Val * Last) / (Count + (Val * Last))           Last = B      Next Count ErlangBExit:      ErlangB = MinMax(B, 0, 1)      Exit Function  ErlangBError:      B = 0      Resume ErlangBExit End Function``

If I am understanding correctly the variable ErlangB is returned from the above function. But, if this is the case, what is the point of stepping into the loop

``For Count = 1 To MaxIterate               B = (Val * Last) / (Count + (Val * Last))               Last = B          Next Count``

and calculating the variable "last" ?

PS. I have to write the Perl equivalent

``sub     erlangb {         my \$servers = \$_[0] ;         my \$intensity = \$_[1] ;          my \$erlangb_rc = 0 ;         if( \$servers<0 || \$intensity<0 )        { \$erlangb_rc = 0 ; return \$erlangb_rc ; }         my \$maxiterate = int(\$servers) ; my \$val = \$intensity ; my \$last = 1 ;         for( my \$count=1; \$count<=\$maxiterate; \$count++ )       { my \$b = (\$val*\$last)/(\$count+(\$val*\$last)) ; \$last = \$b ; }          return  \$erlangb_rc ; }``

Thank You.

here is and the MinMax function

Private Function MinMax(Val As Single, Min As Single, Max As Single) As Single 'Apply minimum and maximum bounds to a value MinMax = Val If Val < Min Then MinMax = Min If Val > Max Then MinMax = Max End Function

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.