1

I am trying to write a program that calculates the yearly depreciation cost with Financial.DDB function. I need to display the year and depreciation for that year in a listbox. Here is what I have so far:

Public Class Form1


Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    'Displays 1-20 in list box
    For intUsefullife As Integer = 1 To 20
        lstUsefullife.Items.Add(intUsefullife.ToString)
    Next intUsefullife
End Sub


Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    'set variables
    Dim decAssetcost As Decimal
    Dim intUsefullife As Integer
    Dim decSalvage As Decimal
    Dim decSchedule As Decimal

    'parse text boxes
    Integer.TryParse(lstUsefullife.SelectedItem.ToString, intUsefullife)
    Decimal.TryParse(txtAssetcost.Text, decAssetcost)
    Decimal.TryParse(txtSalvage.Text, decSalvage)

    'converts decSchedule to strings
    txtSchedule.Text = decSchedule.ToString


    'Name Headers
    txtSchedule.Text = "Year" & ControlChars.Tab & "Depreciation" & ControlChars.NewLine


    'Calculates depreciation schedule
    For intUsefullife = 1 To intUsefullife Step 1
        txtSchedule.Text = txtSchedule.Text &
            ControlChars.Tab & intUsefullife.ToString

        For decSchedule = Financial.DDB(decAssetcost, decSalvage, intUsefullife, intUsefullife)
            txtSchedule.Text = txtSchedule.Text &
                ControlChars.NewLine
                ControlChars.Tab & decSchedule.ToString("C2") & ControlChars.NewLine
        Next decSchedule
    Next intUsefullife

End Sub

Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
    Me.Close()
End Sub
End Class

I have no idea where to go from here. All that happens when I hit debug and then calculate is year 1 and $0.00 under the depreciation amount. (the year does not display where I want it to either).

4

0 回答 0