Previous Page

Staight-Line and Double-Declining Depreciation to a Salvage of Zero
-- Visual Basic --

Below is the code, but I usually don't re-name the boxes or buttons....sorry. Guess I probably should.


Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     


        Dim description As String
        Dim yearPurchased As Integer
        Dim cost As Double
        Dim estimatedLife As Integer
        Dim amountDepr As Double
        Dim totalDepr As Double = 0
        Dim fmtStr As String = "{0,2} {1, -10} {2, 10:N2} {3, 22:N2} {4, 25:N2}"


        description = TextBox1.Text

        Try
            yearPurchased = CDbl(TextBox2.Text)
        Catch
            MsgBox("Please enter the Year Purchased in the following format: 2005", vbCritical, "Error!")
            With TextBox2
                .SelectionStart = 0
                .SelectionLength = Len(TextBox2.Text)
                .Focus()
            End With
            ListBox1.Items.Clear()
            Exit Sub

        End Try
        Try
            cost = CDbl(TextBox3.Text)
        Catch
            MsgBox("Please enter only numbers without commas", vbCritical, "Error!")
            With TextBox3
                .SelectionStart = 0
                .SelectionLength = Len(TextBox3.Text)
                .Focus()
            End With
            ListBox1.Items.Clear()
            Exit Sub

        End Try
        Try
            estimatedLife = CDbl(TextBox4.Text)
        Catch
            MsgBox("Please enter only numbers without commas", vbCritical, "Error!")
            With TextBox4
                .SelectionStart = 0
                .SelectionLength = Len(TextBox4.Text)
                .Focus()
            End With
            ListBox1.Items.Clear()
            Exit Sub

        End Try

        ListBox1.Items.Clear()
        ListBox1.Items.Add("")
        ListBox1.Items.Add("   Description: " & description)
        ListBox1.Items.Add("   Year of Purchase: " & yearPurchased)
        ListBox1.Items.Add("   Cost: " & cost)
        ListBox1.Items.Add("   Estimated Life: " & estimatedLife)
        ListBox1.Items.Add("   Method of Depreciation: straight-line method")
        ListBox1.Items.Add("")
        ListBox1.Items.Add(String.Format(fmtStr, "", "", "Value at", "Amount Deprec", "Total Depreciation"))
        ListBox1.Items.Add(String.Format(fmtStr, "", "Year", "Beg of Yr", "During Year", "to End of Year"))

        For i As Integer = 1 To estimatedLife
            amountDepr = cost / estimatedLife
            If i = estimatedLife Then
                amountDepr = cost
            End If
            totalDepr += amountDepr
            ListBox1.Items.Add(String.Format(fmtStr, "", yearPurchased, cost, amountDepr, totalDepr))
            cost -= amountDepr
            yearPurchased += 1
        Next

    End Sub




    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim description As String
        Dim yearPurchased As Integer
        Dim cost As Double
        Dim estimatedLife As Integer
        Dim amountDepr As Double
        Dim totalDepr As Double = 0
        Dim fmtStr As String = "{0,2} {1, -10} {2, 10:N2} {3, 22:N2} {4, 25:N2}"

        description = TextBox1.Text

        Try
            yearPurchased = CDbl(TextBox2.Text)
        Catch
            MsgBox("Please enter the Year Purchased in the following format: 2005", vbCritical, "Error!")
            With TextBox2
                .SelectionStart = 0
                .SelectionLength = Len(TextBox2.Text)
                .Focus()
            End With
            ListBox1.Items.Clear()
            Exit Sub

        End Try
        Try
            cost = CDbl(TextBox3.Text)
        Catch
            MsgBox("Please enter only numbers without commas", vbCritical, "Error!")
            With TextBox3
                .SelectionStart = 0
                .SelectionLength = Len(TextBox3.Text)
                .Focus()
            End With
            ListBox1.Items.Clear()
            Exit Sub

        End Try
        Try
            estimatedLife = CDbl(TextBox4.Text)
        Catch
            MsgBox("Please enter only numbers without commas", vbCritical, "Error!")
            With TextBox4
                .SelectionStart = 0
                .SelectionLength = Len(TextBox4.Text)
                .Focus()
            End With
            ListBox1.Items.Clear()
            Exit Sub

        End Try

        ListBox1.Items.Clear()
        ListBox1.Items.Add("")
        ListBox1.Items.Add("   Description: " & description)
        ListBox1.Items.Add("   Year of Purchase: " & yearPurchased)
        ListBox1.Items.Add("   Cost: " & cost)
        ListBox1.Items.Add("   Estimated Life: " & estimatedLife)
        ListBox1.Items.Add("   Method of Depreciation: double-declining-balance")
        ListBox1.Items.Add("")

        ListBox1.Items.Add(String.Format(fmtStr, "", "", "Value at", "Amount Deprec", "Total Depreciation"))
        ListBox1.Items.Add(String.Format(fmtStr, "", "Year", "Beg of Yr", "During Year", "to End of Year"))

        For i As Integer = 1 To estimatedLife
            amountDepr = (cost / estimatedLife) * 2
            If i = estimatedLife Then
                amountDepr = cost
            End If
            totalDepr += amountDepr
            ListBox1.Items.Add(String.Format(fmtStr, "", yearPurchased, cost, amountDepr, totalDepr))
            cost -= amountDepr
            yearPurchased += 1
        Next
    End Sub
End Class

Below is a sample input/output.

straight line depreciation
double declining