Wannabe Wannabe - 8 months ago 29
Vb.net Question

Financial.DDB Function (VB.Net)

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.


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)