<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="VB6Parse Library Reference - ddb - Financial">
<title>ddb - Financial - VB6Parse Library Reference</title>
<link rel="stylesheet" href="../../../assets/css/style.css">
<link rel="stylesheet" href="../../../assets/css/docs-style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
<script src="../../../assets/js/theme-switcher.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/vbnet.min.js"></script>
<script>hljs.highlightAll();</script>
</head>
<body>
<header class="docs-header">
<div class="container">
<h1><a href="../../../index.html">VB6Parse</a> / <a href="../../../library/index.html">Library</a> / <a href="../../../library/functions/financial/index.html">Financial</a> / ddb</h1>
<p class="tagline">VB6 Library Reference</p>
</div>
</header>
<nav class="docs-nav">
<div class="container">
<a href="../../../index.html">Home</a>
<a href="../../../library/index.html">Library Reference</a>
<a href="../../../documentation.html">Documentation</a>
<a href="https://docs.rs/vb6parse" target="_blank">API Docs</a>
<a href="https://github.com/scriptandcompile/vb6parse" target="_blank">GitHub</a>
<button id="theme-toggle" class="theme-toggle" aria-label="Toggle theme">
<span class="theme-icon">🌙</span>
</button>
</div>
</nav>
<main class="container">
<article class="library-item">
<h1 id="ddb-function">DDB Function</h1>
<p>Returns a Double specifying the depreciation of an asset for a specific time period using
the double-declining balance method or some other method you specify.</p>
<h2 id="syntax">Syntax</h2>
<pre><code class="language-vbnet">DDB(cost, salvage, life, period[, factor])</code></pre>
<h2 id="parameters">Parameters</h2>
<ul>
<li><strong>cost</strong>: Required. Double specifying initial cost of the asset.</li>
<li><strong>salvage</strong>: Required. Double specifying value of the asset at the end of its useful life.</li>
<li><strong>life</strong>: Required. Double specifying length of useful life of the asset.</li>
<li><strong>period</strong>: Required. Double specifying period for which asset depreciation is calculated.</li>
<li><strong>factor</strong>: Optional. Variant specifying rate at which the balance declines. If omitted,
2 (double-declining method) is assumed.</li>
</ul>
<h2 id="return-value">Return Value</h2>
<p>Returns a Double representing the depreciation amount for the specified period. The return
value uses the same time units as the life parameter.</p>
<h2 id="remarks">Remarks</h2>
<p>The <code>DDB</code> function calculates depreciation using the double-declining balance method,
which computes depreciation at an accelerated rate. Depreciation is highest in the first
period and decreases in successive periods.
<strong>Important Characteristics:</strong>
- Uses accelerated depreciation (more in early periods)
- Default factor is 2.0 (double-declining balance)
- Factor of 1.5 gives 150% declining balance
- All arguments must be positive numbers
- The life and period arguments must use the same units (years, months, etc.)
- Depreciation never reduces asset value below salvage value
- More accurate than straight-line for assets that lose value quickly
- Commonly used for tax purposes and financial reporting</p>
<h2 id="formula">Formula</h2>
<p>The double-declining balance method uses:</p>
<pre><code class="language-text">Depreciation = (Book Value - Salvage) × (Factor / Life)
Where:
- Book Value = Cost - Accumulated Depreciation from prior periods
- Factor = Declining balance rate (default 2.0)
- Life = Total useful life of asset</code></pre>
<p>The function ensures that depreciation does not reduce the book value below salvage value.</p>
<h2 id="examples">Examples</h2>
<h3 id="basic-usage">Basic Usage</h3>
<pre><code class="language-vbnet">' Calculate depreciation for equipment
Dim cost As Double
Dim salvage As Double
Dim life As Double
Dim depreciation As Double
cost = 10000 ' $10,000 initial cost
salvage = 1000 ' $1,000 salvage value
life = 5 ' 5 year useful life
' First year depreciation (double-declining)
depreciation = DDB(cost, salvage, life, 1)
' Returns 4000 (40% of 10000)
' Second year depreciation
depreciation = DDB(cost, salvage, life, 2)
' Returns 2400 (40% of 6000)</code></pre>
<h3 id="custom-declining-factor">Custom Declining Factor</h3>
<pre><code class="language-vbnet">' 150% declining balance
Dim depreciation As Double
depreciation = DDB(10000, 1000, 5, 1, 1.5)
' Uses 30% rate instead of 40%
' Straight-line equivalent (factor = 1)
depreciation = DDB(10000, 1000, 5, 1, 1)</code></pre>
<h3 id="complete-depreciation-schedule">Complete Depreciation Schedule</h3>
<pre><code class="language-vbnet">Sub ShowDepreciationSchedule()
Dim cost As Double
Dim salvage As Double
Dim life As Double
Dim period As Integer
Dim depreciation As Double
cost = 10000
salvage = 1000
life = 5
Debug.Print "Year", "Depreciation", "Book Value"
For period = 1 To life
depreciation = DDB(cost, salvage, life, period)
Debug.Print period, Format(depreciation, "Currency"), _
Format(cost - TotalDepreciation(period), "Currency")
Next period
End Sub</code></pre>
<h2 id="common-patterns">Common Patterns</h2>
<h3 id="calculate-total-accumulated-depreciation">Calculate Total Accumulated Depreciation</h3>
<pre><code class="language-vbnet">Function AccumulatedDepreciation(cost As Double, salvage As Double, _
life As Double, currentPeriod As Integer) As Double
Dim total As Double
Dim i As Integer
total = 0
For i = 1 To currentPeriod
total = total + DDB(cost, salvage, life, i)
Next i
AccumulatedDepreciation = total
End Function</code></pre>
<h3 id="calculate-current-book-value">Calculate Current Book Value</h3>
<pre><code class="language-vbnet">Function BookValue(cost As Double, salvage As Double, _
life As Double, currentPeriod As Integer) As Double
Dim accumulated As Double
accumulated = AccumulatedDepreciation(cost, salvage, life, currentPeriod)
BookValue = cost - accumulated
End Function</code></pre>
<h3 id="compare-depreciation-methods">Compare Depreciation Methods</h3>
<pre><code class="language-vbnet">Sub CompareDepreciationMethods(cost As Double, salvage As Double, life As Double)
Dim period As Integer
Dim ddbDepr As Double
Dim slnDepr As Double
Debug.Print "Period", "DDB", "SLN"
For period = 1 To life
ddbDepr = DDB(cost, salvage, life, period)
slnDepr = SLN(cost, salvage, life)
Debug.Print period, Format(ddbDepr, "Currency"), _
Format(slnDepr, "Currency")
Next period
End Sub</code></pre>
<h3 id="monthly-depreciation">Monthly Depreciation</h3>
<pre><code class="language-vbnet">Function MonthlyDDB(cost As Double, salvage As Double, _
lifeYears As Double, month As Integer) As Double
' Calculate depreciation by month instead of year
Dim lifeMonths As Double
lifeMonths = lifeYears * 12
MonthlyDDB = DDB(cost, salvage, lifeMonths, month)
End Function</code></pre>
<h3 id="partial-year-depreciation">Partial Year Depreciation</h3>
<pre><code class="language-vbnet">Function PartialYearDDB(cost As Double, salvage As Double, life As Double, _
year As Integer, monthsInFirstYear As Integer) As Double
' Handle assets purchased mid-year
If year = 1 Then
PartialYearDDB = DDB(cost, salvage, life, 1) * (monthsInFirstYear / 12)
Else
Dim priorYearPartial As Double
Dim currentYearPartial As Double
priorYearPartial = DDB(cost, salvage, life, year - 1) * _
((12 - monthsInFirstYear) / 12)
currentYearPartial = DDB(cost, salvage, life, year) * _
(monthsInFirstYear / 12)
PartialYearDDB = priorYearPartial + currentYearPartial
End If
End Function</code></pre>
<h3 id="depreciation-rate-calculation">Depreciation Rate Calculation</h3>
<pre><code class="language-vbnet">Function DepreciationRate(life As Double, Optional factor As Double = 2) As Double
' Calculate the depreciation rate percentage
DepreciationRate = (factor / life) * 100
End Function
' Usage
rate = DepreciationRate(5) ' Returns 40% for 5-year DDB
rate = DepreciationRate(5, 1.5) ' Returns 30% for 5-year 150% DB</code></pre>
<h3 id="asset-register-with-ddb">Asset Register with DDB</h3>
<pre><code class="language-vbnet">Type Asset
Description As String
Cost As Double
Salvage As Double
Life As Double
PurchaseDate As Date
End Type
Function CalculateAssetDepreciation(asset As Asset, currentYear As Integer) As Double
Dim yearsOwned As Integer
yearsOwned = Year(Date) - Year(asset.PurchaseDate)
If yearsOwned >= currentYear And currentYear <= asset.Life Then
CalculateAssetDepreciation = DDB(asset.Cost, asset.Salvage, _
asset.Life, currentYear)
Else
CalculateAssetDepreciation = 0
End If
End Function</code></pre>
<h3 id="switch-to-straight-line-detection">Switch to Straight-Line Detection</h3>
<pre><code class="language-vbnet">Function ShouldSwitchToSLN(cost As Double, salvage As Double, _
life As Double, period As Integer) As Boolean
' Determine if switching to SLN would give higher depreciation
Dim ddbAmount As Double
Dim slnAmount As Double
Dim bookValue As Double
Dim remainingLife As Double
ddbAmount = DDB(cost, salvage, life, period)
bookValue = BookValue(cost, salvage, life, period - 1)
remainingLife = life - period + 1
slnAmount = (bookValue - salvage) / remainingLife
ShouldSwitchToSLN = (slnAmount > ddbAmount)
End Function</code></pre>
<h3 id="tax-depreciation-calculator">Tax Depreciation Calculator</h3>
<pre><code class="language-vbnet">Function TaxDepreciation(cost As Double, salvage As Double, _
life As Double, taxYear As Integer, _
Optional method As String = "DDB") As Double
Select Case UCase(method)
Case "DDB"
TaxDepreciation = DDB(cost, salvage, life, taxYear)
Case "150DB"
TaxDepreciation = DDB(cost, salvage, life, taxYear, 1.5)
Case "SLN"
TaxDepreciation = SLN(cost, salvage, life)
Case Else
TaxDepreciation = 0
End Select
End Function</code></pre>
<h2 id="advanced-usage">Advanced Usage</h2>
<h3 id="depreciation-schedule-generator">Depreciation Schedule Generator</h3>
<pre><code class="language-vbnet">Function GenerateDepreciationSchedule(cost As Double, salvage As Double, _
life As Double) As Variant
' Returns 2D array: Period, Depreciation, Accumulated, Book Value
Dim schedule() As Variant
Dim period As Integer
Dim depreciation As Double
Dim accumulated As Double
ReDim schedule(1 To life, 1 To 4)
accumulated = 0
For period = 1 To life
depreciation = DDB(cost, salvage, life, period)
accumulated = accumulated + depreciation
schedule(period, 1) = period
schedule(period, 2) = depreciation
schedule(period, 3) = accumulated
schedule(period, 4) = cost - accumulated
Next period
GenerateDepreciationSchedule = schedule
End Function</code></pre>
<h3 id="hybrid-depreciation-method">Hybrid Depreciation Method</h3>
<pre><code class="language-vbnet">Function HybridDepreciation(cost As Double, salvage As Double, _
life As Double, period As Integer) As Double
' Use DDB but switch to SLN when SLN gives higher amount
Dim ddbAmount As Double
Dim slnAmount As Double
Dim bookValue As Double
Dim remainingLife As Double
ddbAmount = DDB(cost, salvage, life, period)
If period > 1 Then
bookValue = BookValue(cost, salvage, life, period - 1)
remainingLife = life - period + 1
slnAmount = (bookValue - salvage) / remainingLife
HybridDepreciation = Application.Max(ddbAmount, slnAmount)
Else
HybridDepreciation = ddbAmount
End If
End Function</code></pre>
<h3 id="multi-asset-depreciation-report">Multi-Asset Depreciation Report</h3>
<pre><code class="language-vbnet">Sub GenerateDepreciationReport(assets() As Asset, fiscalYear As Integer)
Dim i As Integer
Dim totalDepreciation As Double
Dim assetDepreciation As Double
totalDepreciation = 0
Debug.Print "Asset", "Cost", "Life", "Year", "Depreciation"
For i = LBound(assets) To UBound(assets)
Dim yearsSincePurchase As Integer
yearsSincePurchase = fiscalYear - Year(assets(i).PurchaseDate) + 1
If yearsSincePurchase > 0 And yearsSincePurchase <= assets(i).Life Then
assetDepreciation = DDB(assets(i).Cost, assets(i).Salvage, _
assets(i).Life, yearsSincePurchase)
Debug.Print assets(i).Description, _
Format(assets(i).Cost, "Currency"), _
assets(i).Life, _
yearsSincePurchase, _
Format(assetDepreciation, "Currency")
totalDepreciation = totalDepreciation + assetDepreciation
End If
Next i
Debug.Print "Total Depreciation:", Format(totalDepreciation, "Currency")
End Sub</code></pre>
<h3 id="optimal-method-selector">Optimal Method Selector</h3>
<pre><code class="language-vbnet">Function OptimalDepreciationMethod(cost As Double, salvage As Double, _
life As Double, period As Integer, _
taxRate As Double) As String
' Determine which method gives best tax benefit
Dim ddbAmount As Double
Dim slnAmount As Double
Dim ddbTaxSavings As Double
Dim slnTaxSavings As Double
ddbAmount = DDB(cost, salvage, life, period)
slnAmount = SLN(cost, salvage, life)
ddbTaxSavings = ddbAmount * taxRate
slnTaxSavings = slnAmount * taxRate
If ddbTaxSavings > slnTaxSavings Then
OptimalDepreciationMethod = "DDB"
Else
OptimalDepreciationMethod = "SLN"
End If
End Function</code></pre>
<h3 id="financial-statement-generator">Financial Statement Generator</h3>
<pre><code class="language-vbnet">Sub GenerateDepreciationFootnote(cost As Double, salvage As Double, _
life As Double, currentYear As Integer)
Dim schedule As Variant
Dim i As Integer
Debug.Print "Depreciation is calculated using the double-declining balance method:"
Debug.Print "Asset cost: " & Format(cost, "Currency")
Debug.Print "Salvage value: " & Format(salvage, "Currency")
Debug.Print "Useful life: " & life & " years"
Debug.Print
Debug.Print "Year", "Depreciation", "Net Book Value"
For i = 1 To currentYear
Dim depr As Double
Dim bookVal As Double
depr = DDB(cost, salvage, life, i)
bookVal = BookValue(cost, salvage, life, i)
Debug.Print i, Format(depr, "Currency"), Format(bookVal, "Currency")
Next i
End Sub</code></pre>
<h3 id="macrs-alternative-comparison">MACRS Alternative Comparison</h3>
<pre><code class="language-vbnet">Function CompareDDBToMARS(cost As Double, life As Double) As Variant
' Compare DDB to MACRS (Modified Accelerated Cost Recovery System)
' This is simplified; actual MACRS uses specific tables
Dim comparison() As Variant
Dim period As Integer
Dim ddbTotal As Double
Dim salvage As Double
salvage = 0 ' MACRS assumes zero salvage
ReDim comparison(1 To life, 1 To 3)
For period = 1 To life
comparison(period, 1) = period
comparison(period, 2) = DDB(cost, salvage, life, period)
comparison(period, 3) = BookValue(cost, salvage, life, period)
Next period
CompareDDBToMARS = comparison
End Function</code></pre>
<h2 id="error-handling">Error Handling</h2>
<pre><code class="language-vbnet">Function SafeDDB(cost As Double, salvage As Double, life As Double, _
period As Integer, Optional factor As Double = 2) As Variant
On Error GoTo ErrorHandler
' Validate inputs
If cost < 0 Or salvage < 0 Or life <= 0 Or period <= 0 Then
SafeDDB = CVErr(xlErrNum)
Exit Function
End If
If salvage >= cost Then
SafeDDB = 0
Exit Function
End If
If period > life Then
SafeDDB = 0
Exit Function
End If
SafeDDB = DDB(cost, salvage, life, period, factor)
Exit Function
ErrorHandler:
SafeDDB = CVErr(xlErrValue)
End Function</code></pre>
<h3 id="common-errors">Common Errors</h3>
<ul>
<li><strong>Error 5</strong> (Invalid procedure call): Negative values for cost, salvage, life, or period</li>
<li><strong>Error 5</strong>: Life or period equals zero</li>
<li><strong>Error 5</strong>: Salvage value exceeds cost</li>
</ul>
<h2 id="performance-considerations">Performance Considerations</h2>
<ul>
<li><code>DDB</code> involves iterative calculations for periods > 1</li>
<li>Cache results when calculating multiple periods for same asset</li>
<li>For complete schedules, calculate once and store array</li>
<li>More complex than <code>SLN</code> but still efficient</li>
<li>Consider pre-calculating depreciation schedules for reporting</li>
</ul>
<h2 id="best-practices">Best Practices</h2>
<h3 id="validate-parameters">Validate Parameters</h3>
<pre><code class="language-vbnet">' Good - Validate before calculation
If cost > 0 And salvage >= 0 And salvage < cost And life > 0 Then
depreciation = DDB(cost, salvage, life, period)
End If
' Avoid - May cause runtime error
depreciation = DDB(cost, salvage, life, period)</code></pre>
<h3 id="use-consistent-time-units">Use Consistent Time Units</h3>
<pre><code class="language-vbnet">' Good - Both in years
depreciation = DDB(10000, 1000, 5, 2)
' Good - Both in months
depreciation = DDB(10000, 1000, 60, 24)
' Avoid - Mixing units
depreciation = DDB(10000, 1000, 5, 24) ' Mixing years and months</code></pre>
<h3 id="consider-switching-methods">Consider Switching Methods</h3>
<pre><code class="language-vbnet">' Many businesses switch from DDB to SLN mid-life
' to maximize depreciation deductions
If ShouldSwitchToSLN(cost, salvage, life, period) Then
depreciation = CalculateSLNForRemaining(cost, salvage, life, period)
Else
depreciation = DDB(cost, salvage, life, period)
End If</code></pre>
<h3 id="document-depreciation-assumptions">Document Depreciation Assumptions</h3>
<pre><code class="language-vbnet">' Good - Document method and assumptions
' Depreciation calculated using double-declining balance (200%)
' Useful life: 5 years, Salvage: 10% of cost
depreciation = DDB(cost, cost * 0.1, 5, currentYear)</code></pre>
<h2 id="comparison-with-other-functions">Comparison with Other Functions</h2>
<h3 id="ddb-vs-sln">DDB vs SLN</h3>
<pre><code class="language-vbnet">' DDB - Accelerated depreciation (higher early, lower later)
depr = DDB(10000, 1000, 5, 1) ' Returns 4000
' SLN - Straight-line (same every year)
depr = SLN(10000, 1000, 5) ' Returns 1800</code></pre>
<h3 id="ddb-vs-syd">DDB vs SYD</h3>
<pre><code class="language-vbnet">' DDB - Double-declining balance
depr = DDB(10000, 1000, 5, 1) ' Returns 4000
' SYD - Sum-of-years digits (also accelerated)
depr = SYD(10000, 1000, 5, 1) ' Returns 3000</code></pre>
<h3 id="ddb-with-different-factors">DDB with Different Factors</h3>
<pre><code class="language-vbnet">' Double-declining (200%)
depr = DDB(10000, 1000, 5, 1, 2) ' Returns 4000 (40% rate)
' 150% declining balance
depr = DDB(10000, 1000, 5, 1, 1.5) ' Returns 3000 (30% rate)
' Straight-line equivalent
depr = DDB(10000, 1000, 5, 1, 1) ' Returns 1800 (20% rate)</code></pre>
<h2 id="limitations">Limitations</h2>
<ul>
<li>Does not automatically switch to SLN (must implement manually)</li>
<li>Does not handle mid-period purchases automatically</li>
<li>Does not conform to specific tax codes (MACRS, etc.)</li>
<li>Requires manual handling of disposal before end of life</li>
<li>Cannot directly calculate accumulated depreciation (must sum periods)</li>
<li>Does not handle negative depreciation or write-ups</li>
</ul>
<h2 id="related-functions">Related Functions</h2>
<ul>
<li><code>SLN</code>: Straight-line depreciation (constant per period)</li>
<li><code>SYD</code>: Sum-of-years digits depreciation (accelerated)</li>
<li><code>VDB</code>: Variable declining balance (can switch to SLN automatically)</li>
<li><code>FV</code>: Future value (general financial calculation)</li>
<li><code>PV</code>: Present value (general financial calculation)</li>
</ul>
</article>
<div style="margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border-color);">
<p>
<a href="index.html">← Back to Financial</a> |
<a href="../index.html">View all functions</a>
</p>
</div>
</main>
<footer>
<div class="container">
<p>© 2024-2026 VB6Parse Contributors. Licensed under the MIT License.</p>
</div>
</footer>
</body>
</html>