2
votes

Any advice on using the financial.ddb function? I need to display a depreciation schedule in a label using only the financial.ddb function. I am able to show the final depreciated value at the end of the period but I don't know how to show the value for each year in the period.

For example, if the user entered an asset cost of £1,000, a useful life of 4 years and a salvage value of $100 it should display:

Year 1: 500.00

Year 2: 250.00

Year 3: 125.00

Year 4: 25.00

However, my code (below) shows 25.00 for every year.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim cost As Double
    Dim life As Double = CDbl(ComboBox1.SelectedItem)
    Dim salvage As Double
    Dim numberperiod As Integer
    Dim period As Integer
    Dim depreciation As Double
    Dim isconverted1 As Boolean
    Dim isconverted2 As Boolean
    Dim isconverted3 As Boolean

    isconverted1 = Double.TryParse(TextBox1.Text, cost)
    isconverted2 = Double.TryParse(TextBox2.Text, salvage)
    isconverted3 = Integer.TryParse(TextBox3.Text, period)

    For numberperiod = 1 To period Step 1
        depreciation = Financial.DDB(cost, salvage, life, period)
        Label1.Text += numberperiod.ToString & " -> " & Convert.ToString(depreciation) _
        & ControlChars.NewLine
    Next numberperiod

End Sub

Thanks very much for looking at this.

2

2 Answers

2
votes

I think you just want to pass numberperiod into the DDB method instead of period.

depreciation = Financial.DDB(cost, salvage, life, numberperiod)

(Your loop is calling the function with the period as '4' four times instead of 1,2,3,4)

0
votes

Here is the answer for the problem (posted I don't know when) but still, you got it.

Private Sub btnDisplay_Click(sender As System.Object, e As System.EventArgs) Handles btnDisplay.Click
    Dim intAsset As Integer
    Dim intSavage As Integer
    Dim dblDep As Double
    Dim intuseful As Integer
    Dim strHeading As String = "Year  Depreciation"

    txtDep.Text = String.Empty
    Integer.TryParse(txtAsset.Text, intAsset)
    Integer.TryParse(txtSalvage.Text, intSavage)
    Integer.TryParse(lstUseful.Text, intuseful)
    txtDep.Text = txtDep.Text & ControlChars.NewLine

    txtDep.Text = strHeading & ControlChars.NewLine
    For Intterm = 1 To intuseful
        txtDep.Text = txtDep.Text & ControlChars.NewLine & Intterm.ToString & "      "
        dblDep = Financial.DDB(intAsset, intSavage, intuseful, Intterm)
        txtDep.Text = txtDep.Text & dblDep.ToString("c2") & "   "
    Next
End Sub