Question: [Visual Basic] Depreciation to a Salvage Value of 0. For tax purposes an item may be depreciated over a period of several years, n. With
[Visual Basic]
Depreciation to a Salvage Value of 0. 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 1/nth of its original value. With the doubledeclining- balance method of depreciation, each year the item depreciates by 2/nths of its value at the beginning of that year. (In the final year it is depreciated by its value at the beginning of the year.) Write a program that performs the following tasks: (A) Request a description of the item, the year puchased, the cost of the item, the number of years to be dpreciated (estimated life), and the method of depreciation. The method of depreciation should be chosen by clicking on one of two buttons. (B) Validate all the data and produce the following error messages: "Must enter a Description." "Year Purchased is not numeric." "Year Purchased is not between 1900 and 9999" "Purchase Amount is not numeric." "Purchase Amount must be > zero." "Years to Depreciate is not numeric." "Number of years must be between 1 and 999." (C) Displays the year-by-year depreciation similar to examples below. (D) The Restart button will reset program to accept new data.
I think I almost finished the code, but I have two problems with it
1) I have no idea how to show the output on a new window when the user clicks calculate button
2) I just don't know what to calculate for Value at Year, Deprec During Year, and Total Depreciation to End of Year.
The output should look like below:
Date/Time of Report :10/21/2018 8:01:46 PM
Description : abc Year of purchase : 2007 Cost : $50.00 Estimated Life : 5 Method of depreciation: straight-line-balance
Value at Amount Deprec Total Depreciation Year beg of Yr During Year to End of Year
2007 $50.00 $10.00 $10.00 2008 $40.00 $10.00 $20.00 2009 $30.00 $10.00 $30.00 2010 $20.00 $10.00 $40.00 2011 $10.00 $10.00 $50.00
--------------------------------------------------------------------
Date/Time of Report :10/21/2018 8:02:06 PM
Description : abc Year of purchase : 2007 Cost : $50.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
2007 $50.00 $20.00 $20.00 2008 $30.00 $12.00 $32.00 2009 $18.00 $7.20 $39.20 2010 $10.80 $4.32 $43.52 2011 $6.48 $6.48 $50.00
[Here's my code]
Public Class SalvageValueOfZero
Dim description As String Dim yearOfPurchase As Integer Dim cost As Double Dim life As Integer Dim method As String Dim depreciation As Double Dim totalDepreciation As Double
Private Sub btnCalculation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculation.Click
Dim isError As Boolean = False
'To check the Description is empty or not If (txtItemDesc.Text.Trim() = "") Then MsgBox("Must enter a Description.", MsgBoxStyle.Information) isError = True End If
'To check purchase year is numeric If Not IsNumeric(txtYrPurchased.Text) = True And isError = False Then MsgBox("Year Purchased is not numeric.", MsgBoxStyle.Information) isError = True ElseIf isError = False Then Dim purchaseYear As Integer = CInt(Int(txtYrPurchased.Text)) If purchaseYear < 1900 Or purchaseYear > 9999 Then MsgBox("Year Purchased is not between 1900 and 9999.", MsgBoxStyle.Information) isError = True End If End If
'To check purchase amount is numeric If Not IsNumeric(txtAmount.Text) = True And isError = False Then MsgBox("Purchase Amount is not numeric.", MsgBoxStyle.Information) isError = True ElseIf isError = False Then Dim purchaseAmt As Integer = CInt(Int(txtAmount.Text)) If purchaseAmt < 0 Then MsgBox("Purchase Amount must be > zero.", MsgBoxStyle.Information) isError = True End If End If
'To check depreciation year is numeric If Not IsNumeric(txtDepOfYrs.Text) = True And isError = False Then MsgBox("Years to Depreciate is not numeric.", MsgBoxStyle.Information) isError = True ElseIf isError = False Then Dim depYear As Integer = CInt(Int(txtDepOfYrs.Text)) If depYear < 1 Or depYear > 999 Then MsgBox("Number of years must be between 1 and 999.", MsgBoxStyle.Information) isError = True End If End If
'Now if no error then proceed to do the calculation If isError = False Then Dim lsDepreciation As List(Of String) = New List(Of String) End If
If radStraight.Checked = True Then 'assigning "straight-line" to method
method = "straight-line"
'calling writeDescription method
writeDescription()
'calculating depreciation
depreciation = cost / life
'calling YearlyDescription
YearlyDescription()
ElseIf radDouble.Checked = True Then
'assigning "straight-line" to method
method = "double-declining-balance"
'calling writeDescription method
writeDescription()
'calculating depreciation
depreciation = cost * 2 / life
'calling YearlyDescription
YearlyDescription() End If End Sub
Public Sub writeDescription() Dim intCount As Integer = 0 Dim purAmt As Integer = CInt(Int(txtAmount.Text)) Dim residualAmount As Integer = (purAmt / 100) * 20
Dim depreciationValue As Double = (purAmt - residualAmount) / CInt(Int(txtDepOfYrs.Text))
'getting input
description = txtItemDesc.Text
yearOfPurchase = CInt(txtYrPurchased.Text)
cost = CDbl(txtAmount.Text)
life = CInt(txtDepOfYrs.Text)
'adding item description to list box
lstCalculation.Items.Clear()
lstCalculation.Items.Add("Date/Time of Report :" & DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")) lstCalculation.Items.Add("Description: " & description) lstCalculation.Items.Add("Year of purchase: " & yearOfPurchase) lstCalculation.Items.Add("Cost: " & FormatCurrency(cost)) lstCalculation.Items.Add("Estimated life: " & life) lstCalculation.Items.Add("Method of depreciation :" & method) lstCalculation.Items.Add("")
lstCalculation.Items.Add(" " & "Value at" & " " & "Amount Deprec" & " " & "Total Depreciation") lstCalculation.Items.Add("Year" & " " & "beg of Yr" & " " & " " & "to End of Year") lstCalculation.Items.Add("") For intCount = 0 To life lstCalculation.Items.Add(yearOfPurchase + intCount & " " & purAmt &) intCount += 1 Next End Sub
Public Sub YearlyDescription()
totalDepreciation = 0
'running loop from the year of purchase to life times
Dim j As Integer = yearOfPurchase + life
For year As Integer = yearOfPurchase To j
lstCalculation.Items.Add("Value at begining of " & year & ": " & FormatCurrency(cost))
'decreasing cost
cost -= depreciation
lstCalculation.Items.Add("Amount of depreciation during " & year & ": " & FormatCurrency(depreciation))
'increasing total depreciation
totalDepreciation += depreciation
lstCalculation.Items.Add("Total depreciation at end of " & year & ": " & FormatCurrency(totalDepreciation))
lstCalculation.Items.Add("")
Next
End Sub 'Reset button click event which clears all the data in controls Private Sub btnRestart_Click(sender As Object, e As EventArgs) Handles btnRestart.Click txtItemDesc.Text = "" txtYrPurchased.Text = "" txtDepOfYrs.Text = "" txtAmount.Text = "" radStraight.Checked = True lstCalculation.Items.Clear() End Sub
'Exit button Click Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnClose.Click Me.Close() End Sub
End Class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
