Click here to Skip to main content
15,883,795 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
Below is my SYD code which work fine but not accurate. And I want some one to help me get it right. The problem I'm face here is that the code can only calculate for the first two years but the rest of years goes of track.

Thanks in advance.

VB
Private Sub SumOfYear()

Try

    TextBox1.Text = CStr((CDbl(TxtLife.Text) * (CDbl(TxtLife.Text) + 1)) / 2)

    Catch oex As Exception
        MessageBox.Show(" Enter a number ")
    End Try

    TextBox1.Text = Math.Round(Convert.ToDecimal(TxtLife.Text), 2) / Math.Round(Convert.ToDecimal(TextBox1.Text), 2) * 100

    TextBox1.Text = Math.Round(Convert.ToDecimal(TextBox1.Text), 4)

    Dim value As String = TextBox1.Text
    Dim num As Double
    If Double.TryParse(value, num) Then
        Dim percentage As Double = num / 100
        TextBox2.Text = percentage.ToString()
    Else
        ' cannot parse the given string to a double
    End If


    Dim yearpurchased, cost, scrap, life, life2, Deprec, Accumdeprec, begvalue, endgvalue As Double
    Dim item As String
    Dim fmt As String = "{0,-7}{1,10}{2,16}{3,20}{4,20}"
    Dim numberyears As Integer

    item = txtItem.Text
    yearpurchased = txtYear.Text
    cost = TxtCost.Text
    scrap = txtscrap.Text
    life = TxtLife.Text
    life2 = TxtLife.Text

    listDepreciation.Items.Clear()
    listDepreciation.Items.Add(" ")

    listDepreciation.Items.Add(String.Format(fmt, "Year", "Beg of Yr", "During Year", "Accum Deprec", "to End of Year"))

    begvalue = cost
    Deprec = (cost - scrap) * TextBox2.Text
    Accumdeprec = (Accumdeprec + Deprec)
    endgvalue = begvalue - Deprec

    For numberyears = 1 To life2
        listDepreciation.Items.Add(String.Format(fmt, _
                        yearpurchased, _
                        FormatNumber(begvalue), _
                        FormatNumber(Deprec), _
                        FormatNumber(Accumdeprec), _
                        FormatNumber(endgvalue)))


        begvalue = endgvalue
        Deprec = (cost - scrap) * TextBox2.Text
        Accumdeprec = (Accumdeprec + Deprec)
        endgvalue = begvalue - Deprec

        If numberyears = life - 1 Then
            Deprec = (cost - scrap) * TextBox2.Text
            endgvalue = begvalue - Deprec
        End If
        yearpurchased = yearpurchased + 1
    Next

End Sub
Posted
Updated 17-Mar-14 23:22pm
v2
Comments
Mathiudi 18-Mar-14 9:54am    
so no one show interest in my problem. OK thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900