# DDB 函數

DDB ( 成本、 殘餘、 生命週期 [、 因子變異數]

DDB函數語法具有下列引數：

DDB函數來計算指定期間內的折舊，使用下列公式：

## 範例

``` Dim Fmt, InitCost, SalvageVal, MonthLife, LifeTime, DepYear, DeprConst YRMOS = 12 ' Number of months in a year.Fmt = "###,##0.00"InitCost = InputBox("What's the initial cost of the asset?")SalvageVal = InputBox("Enter the asset's value at end of its life.")MonthLife = InputBox("What's the asset's useful life in months?")Do While MonthLife < YRMOS ' Ensure period is >= 1 year. MsgBox "Asset life must be a year or more." MonthLife = InputBox("What's the asset's useful life in months?")LoopLifeTime = MonthLife / YRMOS ' Convert months to years.If LifeTime <> Int(MonthLife / YRMOS) Then LifeTime = Int(LifeTime + 1) ' Round up to nearest year.End If DepYear = CInt(InputBox("Enter year for depreciation calculation."))Do While DepYear < 1 Or DepYear > LifeTime MsgBox "You must enter at least 1 but not more than " & LifeTime DepYear = InputBox("Enter year for depreciation calculation.")LoopDepr = DDB(InitCost, SalvageVal, LifeTime, DepYear)MsgBox "The depreciation for year " & DepYear & " is " & _Format(Depr, Fmt) & "." ```

×