Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

Depreciation Question

$
0
0
For tax purposes in item may be depreciated over a period of several years, n. With the straight line method of depreciation, each year the item depreciates by 1/nth of its original value. With the double declining balance method of depreciation, each year the item depreciates by 2/nth of its value at the beginning of the year. Write a program that performs the following:
1. Request a description of the item, the year of purchase, the cost of the item, the number of years to be depreciated, and the method of depreciation. The method of depreciation should be chosen by clicking on one of the two buttons
2. Display a year-by-year description of the depreciation

When I run the program, I feel like there is a looping problem. Nothing displays on the listbox and the screen freezes. Any suggestions?

Private Sub S23btnStrLine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S23btnStrLine.Click
Dim S23Depr As String = "Straight Line"
S23lstOutput.Items.Clear()
S23Description()
S23Header(S23Depr)
End Sub

Private Sub S23btnDDBM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S23btnDDBM.Click
Dim S23Depr As String = "Double Declining Balance"
S23lstOutput.Items.Clear()
S23Description()
S23Header(S23Depr)
End Sub
Sub S23Description()
If IsNumeric(S23txtYear.Text) And IsNumeric(S23txtCost.Text) And IsNumeric(S23txtLife.Text) And S23txtItem.Text <> "" And S23txtYear.Text <> "" And S23txtCost.Text <> "" And S23txtLife.Text <> "" And (CDbl(S23txtYear.Text) > 0) And (CDbl(S23txtCost.Text) > 0) And (CDbl(S23txtLife.Text) > 0) Then
MessageBox.Show("Thank you for entering your information.")
Else
MessageBox.Show("Please enter the correct information.")
End If
End Sub
Sub S23Header(ByVal S23Depr As String)
Dim S23item As String
Dim S23year, S23life As Integer
Dim S23cost As Double

S23item = CStr(S23txtItem.Text)
S23year = CInt(S23txtYear.Text)
S23cost = CDbl(S23txtCost.Text)
S23life = CInt(S23txtYear.Text)

S23lstOutput.Items.Add("Desciption: " & S23item)
S23lstOutput.Items.Add("Year of purchase: " & S23year)
S23lstOutput.Items.Add("Cost: " & S23cost)
S23lstOutput.Items.Add("Estimated life: " & S23life)
S23lstOutput.Items.Add("Method of depreciation: " & S23Depr)
If S23Depr = "Staight Line" Then
S23Straightline(S23year, S23cost, S23life)
Else
S23Doubledecline(S23year, S23cost, S23life)
End If
End Sub
Sub S23Straightline(ByVal S23year As Integer, ByVal S23cost As Double, ByVal S23life As Integer)
Dim S23depreciation As Double
Dim S23accumDepr As Double = 0
Dim S23currentValue As Double
Dim S23beginValue As Double
S23year = S23year - 1

Do
S23depreciation = S23cost * (1 / S23life)
S23accumDepr = S23accumDepr + S23depreciation
S23currentValue = S23cost - S23accumDepr
S23beginValue = S23currentValue + S23depreciation
S23year += 1
S23lstOutput.Items.Add("Value at beginning of " & S23year & ":" & FormatCurrency(S23beginValue))
S23lstOutput.Items.Add("Amount of depreciation during " & S23year & ":" & FormatCurrency(S23depreciation))
S23lstOutput.Items.Add("Total depreciation at end of " & S23year & ":" & FormatCurrency(S23accumDepr))
S23lstOutput.Items.Add("")

Loop Until S23currentValue <= 0
End Sub
Sub S23Doubledecline(ByVal S23year As Integer, ByVal S23cost As Double, ByVal S23life As Integer)
Dim S23depreciation As Double
Dim S23accumDepr As Double = 0
Dim S23currentValue As Double
Dim S23beginValue As Double
S23year = S23year - 1

Do
S23depreciation = S23beginValue * (2 / S23beginValue)
S23accumDepr = S23accumDepr + S23depreciation
S23currentValue = S23cost - S23accumDepr
S23beginValue = S23currentValue + S23depreciation
S23year += 1
If S23depreciation >= S23currentValue Then
S23depreciation = S23currentValue
End If
S23lstOutput.Items.Add("Value at beginning of " & S23year & ":" & FormatCurrency(S23beginValue))
S23lstOutput.Items.Add("Amount of depreciation during " & S23year & ":" & FormatCurrency(S23depreciation))
S23lstOutput.Items.Add("Total depreciation at end of " & S23year & ":" & FormatCurrency(S23accumDepr))
S23lstOutput.Items.Add("")


Loop Until S23currentValue <= 0
End Sub

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>