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.
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
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