vb6parse 1.0.0

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
<!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 - syd - Financial">
    <title>syd - 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> / syd</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">
            <p>VB6 SYD Function
The <code>SYD</code> function returns a Double specifying the sum-of-years digits depreciation of an asset for a specified period.</p>
<h2 id="syntax">Syntax</h2>
<pre><code class="language-vbnet">SYD(cost, salvage, life, period)</code></pre>
<h2 id="parameters">Parameters</h2>
<ul>
<li><code>cost</code>: Required. Double specifying initial cost of the asset.</li>
<li><code>salvage</code>: Required. Double specifying value of the asset at the end of its useful life.</li>
<li><code>life</code>: Required. Double specifying length of the useful life of the asset.</li>
<li><code>period</code>: Required. Double specifying period for which asset depreciation is calculated.
All arguments must be positive numbers. The <code>period</code> argument must be in the same units as the <code>life</code> argument.</li>
</ul>
<h2 id="returns">Returns</h2>
<p>Returns a <code>Double</code> specifying the depreciation of an asset for a specific period when using the sum-of-years digits method.</p>
<h2 id="remarks">Remarks</h2>
<p>The <code>SYD</code> function calculates depreciation using the sum-of-years digits method:
- <strong>Accelerated depreciation</strong>: More depreciation in early years, less in later years
- <strong>Sum-of-years calculation</strong>: For life of 5 years, sum = 5+4+3+2+1 = 15
- <strong>Period weighting</strong>: Year 1 uses 5/15, Year 2 uses 4/15, etc.
- <strong>Formula</strong>: <code>SYD = ((cost - salvage) * (life - period + 1) * 2) / (life * (life + 1))</code>
- <strong>Depreciable base</strong>: <code>cost - salvage</code> (total amount to depreciate)
- <strong>Declining fraction</strong>: Remaining life / sum-of-years digits
- <strong>Period must be valid</strong>: Must be between 1 and <code>life</code> (inclusive)
- <strong>Consistent units</strong>: <code>period</code> and <code>life</code> must use same time units (years, months, etc.)</p>
<h3 id="sum-of-years-digits-method">Sum-of-Years Digits Method</h3>
<p>The sum-of-years digits (SYD) method is an accelerated depreciation technique:
1. Calculate the sum of all years: <code>sum = life * (life + 1) / 2</code>
2. For each period, the depreciation fraction is: <code>(life - period + 1) / sum</code>
3. Multiply the fraction by the depreciable amount: <code>(cost - salvage)</code></p>
<h3 id="example-calculation">Example Calculation</h3>
<p>For an asset with cost=$10,000, salvage=$1,000, life=5 years:
- Depreciable amount = $10,000 - $1,000 = $9,000
- Sum of years = 5+4+3+2+1 = 15
- Year 1: 5/15 × $9,000 = $3,000
- Year 2: 4/15 × $9,000 = $2,400
- Year 3: 3/15 × $9,000 = $1,800
- Year 4: 2/15 × $9,000 = $1,200
- Year 5: 1/15 × $9,000 = $600
- Total: $9,000 (fully depreciated to salvage value)</p>
<h3 id="when-to-use-syd">When to Use SYD</h3>
<ul>
<li><strong>Technology assets</strong>: Equipment that loses value quickly initially</li>
<li><strong>Vehicles</strong>: Cars and trucks that depreciate faster when new</li>
<li><strong>Tax advantages</strong>: When accelerated depreciation provides tax benefits</li>
<li><strong>Matching principle</strong>: When asset productivity is higher in early years</li>
<li><strong>Alternative to DDB</strong>: Less aggressive than double-declining balance</li>
</ul>
<h2 id="typical-uses">Typical Uses</h2>
<ol>
<li><strong>Asset Depreciation</strong>: Calculate annual depreciation for financial statements</li>
<li><strong>Tax Calculations</strong>: Determine tax-deductible depreciation amounts</li>
<li><strong>Book Value Tracking</strong>: Track declining book value of assets over time</li>
<li><strong>Financial Reporting</strong>: Generate depreciation schedules for reports</li>
<li><strong>Budget Planning</strong>: Estimate future depreciation expenses</li>
<li><strong>Asset Management</strong>: Track depreciation for multiple assets</li>
<li><strong>Comparison Analysis</strong>: Compare SYD with straight-line or DDB methods</li>
<li><strong>Period Calculations</strong>: Calculate depreciation for partial periods</li>
</ol>
<h2 id="basic-examples">Basic Examples</h2>
<h3 id="example-1-simple-annual-depreciation">Example 1: Simple Annual Depreciation</h3>
<pre><code class="language-vbnet">Dim depreciation As Double
Dim cost As Double
Dim salvage As Double
Dim life As Double
Dim year As Double
cost = 10000      &#x27; Initial cost
salvage = 1000    &#x27; Salvage value
life = 5          &#x27; 5-year life
year = 1          &#x27; First year
depreciation = SYD(cost, salvage, life, year)
&#x27; depreciation = 3000 (5/15 of 9000)</code></pre>
<h3 id="example-2-complete-depreciation-schedule">Example 2: Complete Depreciation Schedule</h3>
<pre><code class="language-vbnet">Sub ShowDepreciationSchedule()
    Dim cost As Double
    Dim salvage As Double
    Dim life As Integer
    Dim year As Integer
    Dim depreciation As Double
    Dim totalDep As Double
    cost = 50000
    salvage = 5000
    life = 10
    totalDep = 0
    For year = 1 To life
        depreciation = SYD(cost, salvage, life, year)
        totalDep = totalDep + depreciation
        Debug.Print &quot;Year &quot; &amp; year &amp; &quot;: $&quot; &amp; Format$(depreciation, &quot;#,##0.00&quot;)
    Next year
    Debug.Print &quot;Total Depreciation: $&quot; &amp; Format$(totalDep, &quot;#,##0.00&quot;)
End Sub</code></pre>
<h3 id="example-3-monthly-depreciation">Example 3: Monthly Depreciation</h3>
<pre><code class="language-vbnet">Function CalculateMonthlyDepreciation(cost As Double, salvage As Double, _
                                      lifeYears As Integer, month As Integer) As Double
    Dim lifeMonths As Integer
    lifeMonths = lifeYears * 12
    &#x27; Calculate depreciation for the specific month
    CalculateMonthlyDepreciation = SYD(cost, salvage, lifeMonths, month)
End Function</code></pre>
<h3 id="example-4-book-value-calculation">Example 4: Book Value Calculation</h3>
<pre><code class="language-vbnet">Function CalculateBookValue(cost As Double, salvage As Double, _
                           life As Integer, currentPeriod As Integer) As Double
    Dim period As Integer
    Dim totalDepreciation As Double
    totalDepreciation = 0
    For period = 1 To currentPeriod
        totalDepreciation = totalDepreciation + SYD(cost, salvage, life, period)
    Next period
    CalculateBookValue = cost - totalDepreciation
End Function</code></pre>
<h2 id="common-patterns">Common Patterns</h2>
<h3 id="pattern-1-depreciation-schedule-generator">Pattern 1: Depreciation Schedule Generator</h3>
<pre><code class="language-vbnet">Function GenerateDepreciationSchedule(cost As Double, salvage As Double, _
                                      life As Integer) As Variant
    Dim schedule() As Double
    Dim period As Integer
    ReDim schedule(1 To life)
    For period = 1 To life
        schedule(period) = SYD(cost, salvage, life, period)
    Next period
    GenerateDepreciationSchedule = schedule
End Function</code></pre>
<h3 id="pattern-2-partial-year-depreciation">Pattern 2: Partial Year Depreciation</h3>
<pre><code class="language-vbnet">Function CalculatePartialYearDepreciation(cost As Double, salvage As Double, _
                                         life As Integer, year As Integer, _
                                         monthsInYear As Integer) As Double
    Dim fullYearDep As Double
    fullYearDep = SYD(cost, salvage, life, year)
    CalculatePartialYearDepreciation = fullYearDep * (monthsInYear / 12)
End Function</code></pre>
<h3 id="pattern-3-remaining-depreciable-amount">Pattern 3: Remaining Depreciable Amount</h3>
<pre><code class="language-vbnet">Function GetRemainingDepreciation(cost As Double, salvage As Double, _
                                  life As Integer, currentPeriod As Integer) As Double
    Dim period As Integer
    Dim accumulatedDep As Double
    accumulatedDep = 0
    For period = 1 To currentPeriod
        accumulatedDep = accumulatedDep + SYD(cost, salvage, life, period)
    Next period
    GetRemainingDepreciation = (cost - salvage) - accumulatedDep
End Function</code></pre>
<h3 id="pattern-4-compare-depreciation-methods">Pattern 4: Compare Depreciation Methods</h3>
<pre><code class="language-vbnet">Sub CompareDepreciationMethods(cost As Double, salvage As Double, life As Integer)
    Dim period As Integer
    Dim sydDep As Double
    Dim slnDep As Double
    Dim ddbDep As Double
    Debug.Print &quot;Period&quot;, &quot;SYD&quot;, &quot;SLN&quot;, &quot;DDB&quot;
    For period = 1 To life
        sydDep = SYD(cost, salvage, life, period)
        slnDep = SLN(cost, salvage, life)
        ddbDep = DDB(cost, salvage, life, period)
        Debug.Print period, Format$(sydDep, &quot;#,##0.00&quot;), _
                    Format$(slnDep, &quot;#,##0.00&quot;), _
                    Format$(ddbDep, &quot;#,##0.00&quot;)
    Next period
End Sub</code></pre>
<h3 id="pattern-5-quarterly-depreciation">Pattern 5: Quarterly Depreciation</h3>
<pre><code class="language-vbnet">Function GetQuarterlyDepreciation(cost As Double, salvage As Double, _
                                 lifeYears As Integer, quarter As Integer) As Double
    Dim lifeQuarters As Integer
    lifeQuarters = lifeYears * 4
    GetQuarterlyDepreciation = SYD(cost, salvage, lifeQuarters, quarter)
End Function</code></pre>
<h3 id="pattern-6-accumulated-depreciation">Pattern 6: Accumulated Depreciation</h3>
<pre><code class="language-vbnet">Function GetAccumulatedDepreciation(cost As Double, salvage As Double, _
                                   life As Integer, throughPeriod As Integer) As Double
    Dim period As Integer
    Dim total As Double
    total = 0
    For period = 1 To throughPeriod
        total = total + SYD(cost, salvage, life, period)
    Next period
    GetAccumulatedDepreciation = total
End Function</code></pre>
<h3 id="pattern-7-depreciation-percentage">Pattern 7: Depreciation Percentage</h3>
<pre><code class="language-vbnet">Function GetDepreciationPercentage(cost As Double, salvage As Double, _
                                  life As Integer, period As Integer) As Double
    Dim depreciableBase As Double
    Dim periodDep As Double
    depreciableBase = cost - salvage
    periodDep = SYD(cost, salvage, life, period)
    If depreciableBase &gt; 0 Then
        GetDepreciationPercentage = (periodDep / depreciableBase) * 100
    Else
        GetDepreciationPercentage = 0
    End If
End Function</code></pre>
<h3 id="pattern-8-multi-asset-depreciation">Pattern 8: Multi-Asset Depreciation</h3>
<pre><code class="language-vbnet">Function CalculateTotalDepreciation(costs() As Double, salvages() As Double, _
                                   lives() As Integer, period As Integer) As Double
    Dim i As Integer
    Dim total As Double
    total = 0
    For i = LBound(costs) To UBound(costs)
        total = total + SYD(costs(i), salvages(i), lives(i), period)
    Next i
    CalculateTotalDepreciation = total
End Function</code></pre>
<h3 id="pattern-9-validate-depreciation-parameters">Pattern 9: Validate Depreciation Parameters</h3>
<pre><code class="language-vbnet">Function ValidateDepreciationParams(cost As Double, salvage As Double, _
                                   life As Double, period As Double) As Boolean
    ValidateDepreciationParams = (cost &gt; 0) And (salvage &gt;= 0) And _
                                 (life &gt; 0) And (period &gt; 0) And _
                                 (period &lt;= life) And (cost &gt; salvage)
End Function</code></pre>
<h3 id="pattern-10-format-depreciation-report">Pattern 10: Format Depreciation Report</h3>
<pre><code class="language-vbnet">Function FormatDepreciationLine(period As Integer, cost As Double, _
                               salvage As Double, life As Integer) As String
    Dim depreciation As Double
    Dim accumulated As Double
    Dim bookValue As Double
    Dim i As Integer
    depreciation = SYD(cost, salvage, life, period)
    accumulated = 0
    For i = 1 To period
        accumulated = accumulated + SYD(cost, salvage, life, i)
    Next i
    bookValue = cost - accumulated
    FormatDepreciationLine = Format$(period, &quot;0&quot;) &amp; vbTab &amp; _
                            Format$(depreciation, &quot;#,##0.00&quot;) &amp; vbTab &amp; _
                            Format$(accumulated, &quot;#,##0.00&quot;) &amp; vbTab &amp; _
                            Format$(bookValue, &quot;#,##0.00&quot;)
End Function</code></pre>
<h2 id="advanced-usage">Advanced Usage</h2>
<h3 id="example-1-asset-depreciation-manager-class">Example 1: Asset Depreciation Manager Class</h3>
<pre><code class="language-vbnet">&#x27; Class: AssetDepreciationManager
&#x27; Manages depreciation calculations for assets using SYD method
Option Explicit
Private m_Cost As Double
Private m_Salvage As Double
Private m_Life As Integer
Private m_CurrentPeriod As Integer
Public Sub Initialize(cost As Double, salvage As Double, life As Integer)
    If cost &lt;= salvage Then
        Err.Raise 5, , &quot;Cost must be greater than salvage value&quot;
    End If
    If life &lt;= 0 Then
        Err.Raise 5, , &quot;Life must be greater than zero&quot;
    End If
    m_Cost = cost
    m_Salvage = salvage
    m_Life = life
    m_CurrentPeriod = 0
End Sub
Public Function GetDepreciation(period As Integer) As Double
    If period &lt; 1 Or period &gt; m_Life Then
        Err.Raise 5, , &quot;Period must be between 1 and &quot; &amp; m_Life
    End If
    GetDepreciation = SYD(m_Cost, m_Salvage, m_Life, period)
End Function
Public Function GetAccumulatedDepreciation(throughPeriod As Integer) As Double
    Dim period As Integer
    Dim total As Double
    total = 0
    For period = 1 To throughPeriod
        total = total + GetDepreciation(period)
    Next period
    GetAccumulatedDepreciation = total
End Function
Public Function GetBookValue(atPeriod As Integer) As Double
    GetBookValue = m_Cost - GetAccumulatedDepreciation(atPeriod)
End Function
Public Function GetDepreciationSchedule() As Variant
    Dim schedule() As Variant
    Dim period As Integer
    Dim accumulated As Double
    ReDim schedule(0 To m_Life, 0 To 3) &#x27; Period, Depreciation, Accumulated, Book Value
    schedule(0, 0) = &quot;Period&quot;
    schedule(0, 1) = &quot;Depreciation&quot;
    schedule(0, 2) = &quot;Accumulated&quot;
    schedule(0, 3) = &quot;Book Value&quot;
    accumulated = 0
    For period = 1 To m_Life
        Dim dep As Double
        dep = GetDepreciation(period)
        accumulated = accumulated + dep
        schedule(period, 0) = period
        schedule(period, 1) = dep
        schedule(period, 2) = accumulated
        schedule(period, 3) = m_Cost - accumulated
    Next period
    GetDepreciationSchedule = schedule
End Function
Public Property Get Cost() As Double
    Cost = m_Cost
End Property
Public Property Get SalvageValue() As Double
    SalvageValue = m_Salvage
End Property
Public Property Get UsefulLife() As Integer
    UsefulLife = m_Life
End Property</code></pre>
<h3 id="example-2-depreciation-calculator-module">Example 2: Depreciation Calculator Module</h3>
<pre><code class="language-vbnet">&#x27; Module: DepreciationCalculator
&#x27; Provides comprehensive depreciation calculation utilities
Option Explicit
Public Function CalculateFullSchedule(cost As Double, salvage As Double, _
                                     life As Integer) As String
    Dim period As Integer
    Dim output As String
    Dim depreciation As Double
    Dim accumulated As Double
    Dim bookValue As Double
    output = &quot;Period&quot; &amp; vbTab &amp; &quot;Depreciation&quot; &amp; vbTab &amp; _
             &quot;Accumulated&quot; &amp; vbTab &amp; &quot;Book Value&quot; &amp; vbCrLf
    output = output &amp; String(60, &quot;-&quot;) &amp; vbCrLf
    accumulated = 0
    For period = 1 To life
        depreciation = SYD(cost, salvage, life, period)
        accumulated = accumulated + depreciation
        bookValue = cost - accumulated
        output = output &amp; period &amp; vbTab &amp; _
                 Format$(depreciation, &quot;$#,##0.00&quot;) &amp; vbTab &amp; _
                 Format$(accumulated, &quot;$#,##0.00&quot;) &amp; vbTab &amp; _
                 Format$(bookValue, &quot;$#,##0.00&quot;) &amp; vbCrLf
    Next period
    CalculateFullSchedule = output
End Function
Public Function CompareToStraightLine(cost As Double, salvage As Double, _
                                     life As Integer, period As Integer) As Double
    Dim sydDep As Double
    Dim slnDep As Double
    sydDep = SYD(cost, salvage, life, period)
    slnDep = SLN(cost, salvage, life)
    CompareToStraightLine = sydDep - slnDep
End Function
Public Function CalculateFirstYearDepreciation(cost As Double, salvage As Double, _
                                              life As Integer, _
                                              purchaseMonth As Integer) As Double
    Dim monthsInFirstYear As Integer
    Dim fullYearDep As Double
    monthsInFirstYear = 13 - purchaseMonth
    fullYearDep = SYD(cost, salvage, life, 1)
    CalculateFirstYearDepreciation = fullYearDep * (monthsInFirstYear / 12)
End Function
Public Function GetDepreciationRate(life As Integer, period As Integer) As Double
    Dim sumOfYears As Integer
    Dim remainingLife As Integer
    sumOfYears = life * (life + 1) / 2
    remainingLife = life - period + 1
    GetDepreciationRate = remainingLife / sumOfYears
End Function</code></pre>
<h3 id="example-3-multi-asset-tracker-class">Example 3: Multi-Asset Tracker Class</h3>
<pre><code class="language-vbnet">&#x27; Class: MultiAssetTracker
&#x27; Tracks depreciation for multiple assets
Option Explicit
Private Type AssetInfo
    Name As String
    Cost As Double
    Salvage As Double
    Life As Integer
    PurchaseDate As Date
End Type
Private m_Assets() As AssetInfo
Private m_AssetCount As Integer
Public Sub Initialize()
    m_AssetCount = 0
    ReDim m_Assets(0 To 9)
End Sub
Public Sub AddAsset(name As String, cost As Double, salvage As Double, _
                   life As Integer, purchaseDate As Date)
    If m_AssetCount &gt;= UBound(m_Assets) Then
        ReDim Preserve m_Assets(0 To UBound(m_Assets) * 2)
    End If
    With m_Assets(m_AssetCount)
        .Name = name
        .Cost = cost
        .Salvage = salvage
        .Life = life
        .PurchaseDate = purchaseDate
    End With
    m_AssetCount = m_AssetCount + 1
End Sub
Public Function GetTotalDepreciation(forYear As Integer) As Double
    Dim i As Integer
    Dim total As Double
    Dim period As Integer
    total = 0
    For i = 0 To m_AssetCount - 1
        period = forYear - Year(m_Assets(i).PurchaseDate) + 1
        If period &gt;= 1 And period &lt;= m_Assets(i).Life Then
            total = total + SYD(m_Assets(i).Cost, m_Assets(i).Salvage, _
                               m_Assets(i).Life, period)
        End If
    Next i
    GetTotalDepreciation = total
End Function
Public Function GetAssetDepreciation(assetIndex As Integer, period As Integer) As Double
    If assetIndex &lt; 0 Or assetIndex &gt;= m_AssetCount Then
        Err.Raise 9, , &quot;Invalid asset index&quot;
    End If
    With m_Assets(assetIndex)
        If period &lt; 1 Or period &gt; .Life Then
            GetAssetDepreciation = 0
        Else
            GetAssetDepreciation = SYD(.Cost, .Salvage, .Life, period)
        End If
    End With
End Function
Public Property Get AssetCount() As Integer
    AssetCount = m_AssetCount
End Property</code></pre>
<h3 id="example-4-tax-depreciation-reporter">Example 4: Tax Depreciation Reporter</h3>
<pre><code class="language-vbnet">&#x27; Module: TaxDepreciationReporter
&#x27; Generates tax depreciation reports using SYD method
Option Explicit
Public Function GenerateTaxReport(assetName As String, cost As Double, _
                                 salvage As Double, life As Integer, _
                                 taxYear As Integer) As String
    Dim report As String
    Dim currentYear As Integer
    Dim depreciation As Double
    Dim accumulated As Double
    report = &quot;Tax Depreciation Report - &quot; &amp; assetName &amp; vbCrLf
    report = report &amp; &quot;Method: Sum-of-Years Digits (SYD)&quot; &amp; vbCrLf
    report = report &amp; &quot;Cost: &quot; &amp; Format$(cost, &quot;$#,##0.00&quot;) &amp; vbCrLf
    report = report &amp; &quot;Salvage: &quot; &amp; Format$(salvage, &quot;$#,##0.00&quot;) &amp; vbCrLf
    report = report &amp; &quot;Life: &quot; &amp; life &amp; &quot; years&quot; &amp; vbCrLf &amp; vbCrLf
    accumulated = 0
    For currentYear = 1 To taxYear
        depreciation = SYD(cost, salvage, life, currentYear)
        accumulated = accumulated + depreciation
    Next currentYear
    report = report &amp; &quot;Depreciation for Year &quot; &amp; taxYear &amp; &quot;: &quot; &amp; _
             Format$(SYD(cost, salvage, life, taxYear), &quot;$#,##0.00&quot;) &amp; vbCrLf
    report = report &amp; &quot;Accumulated Depreciation: &quot; &amp; _
             Format$(accumulated, &quot;$#,##0.00&quot;) &amp; vbCrLf
    report = report &amp; &quot;Book Value: &quot; &amp; _
             Format$(cost - accumulated, &quot;$#,##0.00&quot;) &amp; vbCrLf
    GenerateTaxReport = report
End Function
Public Function ExportToCSV(cost As Double, salvage As Double, life As Integer) As String
    Dim csv As String
    Dim period As Integer
    Dim depreciation As Double
    Dim accumulated As Double
    csv = &quot;Period,Depreciation,Accumulated,Book Value&quot; &amp; vbCrLf
    accumulated = 0
    For period = 1 To life
        depreciation = SYD(cost, salvage, life, period)
        accumulated = accumulated + depreciation
        csv = csv &amp; period &amp; &quot;,&quot; &amp; _
              Round(depreciation, 2) &amp; &quot;,&quot; &amp; _
              Round(accumulated, 2) &amp; &quot;,&quot; &amp; _
              Round(cost - accumulated, 2) &amp; vbCrLf
    Next period
    ExportToCSV = csv
End Function
Public Function CalculateTaxSavings(cost As Double, salvage As Double, _
                                   life As Integer, taxRate As Double) As Variant
    Dim period As Integer
    Dim savings() As Double
    Dim depreciation As Double
    ReDim savings(1 To life)
    For period = 1 To life
        depreciation = SYD(cost, salvage, life, period)
        savings(period) = depreciation * taxRate
    Next period
    CalculateTaxSavings = savings
End Function</code></pre>
<h2 id="error-handling">Error Handling</h2>
<p>The <code>SYD</code> function can raise the following errors:
- <strong>Error 5 (Invalid procedure call or argument)</strong>: If any argument is negative, or if <code>period &gt; life</code>, or if <code>cost &lt;= salvage</code>
- <strong>Error 11 (Division by zero)</strong>: If <code>life = 0</code>
- <strong>Error 13 (Type mismatch)</strong>: If arguments are not numeric</p>
<h2 id="performance-notes">Performance Notes</h2>
<ul>
<li>Very fast calculation using direct formula</li>
<li>No iterative computation required (unlike accumulated depreciation)</li>
<li>Constant time O(1) for single period calculation</li>
<li>For full schedule, O(n) where n is the life of the asset</li>
<li>More efficient than DDB for certain tax scenarios</li>
</ul>
<h2 id="best-practices">Best Practices</h2>
<ol>
<li><strong>Validate inputs</strong> before calling SYD (cost &gt; salvage, life &gt; 0, period valid)</li>
<li><strong>Use consistent units</strong> for period and life (both in years, months, or quarters)</li>
<li><strong>Handle salvage = 0</strong> as valid (fully depreciate to zero)</li>
<li><strong>Cache schedules</strong> if calculating multiple periods for same asset</li>
<li><strong>Round appropriately</strong> for financial reporting (typically 2 decimal places)</li>
<li><strong>Document assumptions</strong> about partial periods and mid-year conventions</li>
<li><strong>Compare methods</strong> (SYD, SLN, DDB) to choose appropriate one</li>
<li><strong>Consider tax implications</strong> when choosing depreciation method</li>
<li><strong>Track accumulated depreciation</strong> separately for audit purposes</li>
<li><strong>Validate period range</strong> to avoid errors (1 to life inclusive)</li>
</ol>
<h2 id="comparison-table">Comparison Table</h2>
<table>
<thead>
<tr>
<th>Method</th>
<th>Pattern</th>
<th>Early Years</th>
<th>Later Years</th>
<th>Calculation</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>SYD</strong></td>
<td>Accelerated</td>
<td>Higher</td>
<td>Lower</td>
<td>Sum-of-years formula</td>
</tr>
<tr>
<td><strong>DDB</strong></td>
<td>Accelerated</td>
<td>Highest</td>
<td>Lowest</td>
<td>Double rate</td>
</tr>
<tr>
<td><strong>SLN</strong></td>
<td>Straight-line</td>
<td>Equal</td>
<td>Equal</td>
<td>(Cost-Salvage)/Life</td>
</tr>
</tbody>
</table>
<h2 id="platform-notes">Platform Notes</h2>
<ul>
<li>Available in VB6 and VBA</li>
<li>Not available in <code>VBScript</code></li>
<li>Returns Double precision floating-point</li>
<li>Part of the Financial functions library</li>
<li>Requires all arguments to be positive (except salvage can be zero)</li>
</ul>
<h2 id="limitations">Limitations</h2>
<ul>
<li>Cannot handle negative values for cost, salvage, or life</li>
<li>Period must be between 1 and life (inclusive)</li>
<li>Does not handle mid-period conventions automatically</li>
<li>No built-in support for asset disposals or write-offs</li>
<li>Salvage value must be less than cost</li>
<li>No automatic switching to straight-line method</li>
<li>Does not account for bonus depreciation or special tax rules</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>&copy; 2024-2026 VB6Parse Contributors. Licensed under the MIT License.</p>
        </div>
    </footer>
</body>
</html>