这块vba代码是什么意思?

时间:2015-11-13 17:08:28

标签: vba excel-vba excel

Public Function calcamountpastdueDEV(ByVal creditstatus As String, ByVal user21 As Double, ByVal payoff As Double, ByVal nextdue As Date, ByVal currentdue As Double, ByVal finaldue As Date, _
ByVal payment As Double, ByVal endofdatadate As Date, ByVal principal As Double, ByVal princ_pd As Double, ByVal lfeedue As Double, ByVal prpaydown As Double, ByVal trkstatus As String, ByVal trkacct As String) As Double

' Calculate Amount Past Due
' See comments on each statement

' If it does not meet any of the criteria,
' then set to "-1000" to generate an error.
Dim amountpastdue As Double

amountpastdue = -1000

trkstatus = Trim(trkstatus)
trkacct = Trim(trkacct)

' If these are closed accounts or current account (11) then set to 0.
' CREDIT STATUS comes from the CreditCalculations query.
If creditstatus = 5 Or creditstatus = 11 Or creditstatus = 13 Or creditstatus = 61 Or creditstatus = 62 Or creditstatus = 63 Or creditstatus = 64 Then

    amountpastdue = 0
    GoTo RoundAmountPastDue

End If

' IF Deficiency Balance is greater than 0,
' then use Deficiency Balance.
If user21 > 0 Then

    amountpastdue = user21
    GoTo RoundAmountPastDue

End If

' IF assigned to collections or involuntary repo or charge off,
' then there should be a deficiency balance and we should not have gotten here so
' produce error code -999 for further investigation.
If creditstatus = 95 Or creditstatus = 96 Or creditstatus = 97 Then

    amountpastdue = -999
    GoTo RoundAmountPastDue

End If

' If Credit Status 93 (Account assigned to internal or external collections)
' produce error code -998 for further investigation because we don't want to use this code.
If creditstatus = 93 Then

    amountpastdue = -998
    GoTo RoundAmountPastDue

End If

1 个答案:

答案 0 :(得分:1)

在评论上稍微扩展一下

' If it does not meet any of the criteria,
' then set to "-1000" to generate an error.

设计该函数是为了使返回值为实际计算值(如果> = 0),或错误代码(如果< 0) 。

它将被称为:

x = calcamountpastdueDEV(...)
If x >= 0 Then
    ' do something with the value
Else
    ' handle error code x
End If