# Solved: VB double-declining-balance help pls



## Coke23 (Mar 24, 2010)

i need help with this project. I wrote the code but im getting errors. i dont know what im doing wrong. it wont calculate .can anybody help and fix my code thanks. 
this is the project

For tax purposes an item may be depreciated over a period of several years, n. With the straight-line method of depreciation, each year the item depreciates by l/nth of its original value. With the double-declining-*balance method of depreciation, each year the item depreciates by 2/nths of its value at the beginning of that year. (In the last year, it is depreciated by its value at the beginning of the year.) Write a program that performs the following tasks:

(a) Requests a description of the item, the year of purchase, the cost of the item, the number of years to be depreciated (estimated life), and the method of depreciation. The method of depreciation should be chosen by clicking one of two buttons.

(b) Displays a depreciation schedule for the item similar to the schedule shown below:
Description: Computer
Year of purchase: 2008 
Cost: $2,000.00
Estimated life: 5 
Method of depreciation: double-declining-balance



Value at Amount Deprec Total Depreciation 

Year Beg of Yr During Year to End of Year

2008 2,000.00 800.00 800.00

2009 1,200.00 480.00 1,280.00

2010 720.00 288.00 1,568.00

2011 432.00 172.80 1,740.80

2012 259.20 259.20 2,000.00


----------



## Coke23 (Mar 24, 2010)

This is my code

Public Class Project4
Dim dblCost, dblLife, dblYear, DblDepreciation, dblBegValue, dblEndValue, dblTotal, Counter
Private Sub lstOutput_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstOutput.SelectedIndexChanged

End Sub

Private Sub btnStraight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStraight.Click


' Setting Columns, minus sign indicates left justification, default is right justification
Dim fmtSTR As String = "{0,-22}{1,22}{2,22}{3,22}{4,22}"


'Declare Variables
dblCost = Val(txtCost.Text)
dblLife = Val(txtLife.Text)
dblYear = Val(txtYear.Text)



'Info for List Box
lstOutput.Items.Clear()
lstOutput.Items.Add("Depscription" & txtDescription.Text)
lstOutput.Items.Add("Year of Purchase:" & txtYear.Text)
lstOutput.Items.Add("Cost:" & txtCost.Text)
lstOutput.Items.Add("Estimated Life:" & txtLife.Text)
lstOutput.Items.Add("Method of Deprection: Straight Line")

'Titles for Table in List Box
lstOutput.Items.Add(String.Format(fmtSTR, "Year", "Value at Beg.of Year", "Annual Deprec", "Value at End of Yr.", "Total Depreciation"))

'Declare Loop Counters
Dim intA As Integer




'For Figuring Depreciation
DblDepreciation = dblCost / dblLife


'Fpr Figuring Begining Value
dblBegValue = dblCost
Counter = dblCost - DblDepreciation



'Loop for Straight Life Depreciation
For intA = 1 To dblLife
lstOutput.Items.Add(dblYear)



dblBegValue = dblCost - DblDepreciation
lstOutput.Items.Add(" ")

dblTotal = dblCost - dblEndValue



dblEndValue = dblBegValue - DblDepreciation
Next



End Sub

Private Sub btnDouble_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDouble.Click

' Setting Columbs, minus sign indicates left justification, default is right justification
Dim fmtSTR As String = "{0,-22}{1,22}{2,22}{3,22}{4,22}"

'Declare Variables
dblCost = Val(txtCost.Text)
dblLife = Val(txtLife.Text)
dblYear = Val(txtYear.Text)



'Info for List Box
lstOutput.Items.Clear()
lstOutput.Items.Add("Depscription" & txtDescription.Text)
lstOutput.Items.Add("Year of Purchase:" & txtYear.Text)
lstOutput.Items.Add("Cost:" & txtCost.Text)
lstOutput.Items.Add("Estimated Life:" & txtLife.Text)
lstOutput.Items.Add("Method of Deprection: Double Declining")


'Titles for Table in List Box
lstOutput.Items.Add(String.Format(fmtSTR, "Year", "Value at Beg.of Year", "Annual Deprec", "Value at End of Yr.", "Total Depreciation"))


DblDepreciation = dblCost / dblLife
dblBegValue = dblCost - DblDepreciation
dblEndValue = dblBegValue - DblDepreciation
dblTotal = dblCost - dblEndValue







End Sub


End Class


----------



## Coke23 (Mar 24, 2010)

i got the answer i needed


----------



## ermcse (May 15, 2010)

what was your final code?


----------

