如何在vb.net中计算SYD(年份总和) [英] How to compute SYD (sum of year digit) in vb.net
本文介绍了如何在vb.net中计算SYD(年份总和)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的SYD代码,它工作正常但不准确。我想要一些人来帮助我做对。我在这里面临的问题是,代码只能计算前两年,但其余的年份都是合适的。
提前致谢。
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
' 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
推荐答案
这篇关于如何在vb.net中计算SYD(年份总和)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文