2013-08-31 49 views
1

我的表格应该让某人在直线折旧和双倍折旧余额折旧之间进行选择。直线,我已经想通了,但由于某种原因,我无法让Double-Decline工作。基本上,用户输入项目的年份,成本和预计使用期限,程序向他们显示该项目的年度折旧。折旧计算

所以如果该项目是从2013年开始,花费$ 1000,并且有4年的预期寿命我想输出的样子:在2013年初 价值:$ 1000个 2013年折旧ammount的:$ 500(这是成本的50%) 在2013年年底的总折旧:在2014年初$ 500强

价值:$ 500(成​​本 - 以前的折旧)听英语过程中的折旧 ammount的:$ 250(这是新的50%价值) 2014年底的折旧总额:750美元(这是从今年起的最后一次折旧)

值在2015年开始:(同上。)$ 250 2015期间折旧的 金额:$ 125(新值的50%) 在2015年底总折旧:(同上)$ 857

等。等等,等等

,所以我会附上只是一段代码,我觉得是给我的问题:

Private Sub btnDouble_Click(sender As Object, e As EventArgs) Handles btnDouble.Click 
     lstResults.Items.Clear() 
     lstResults.Items.Add("Description: " & txtItem.Text) 
     lstResults.Items.Add("Year of Purchase: " & txtYear.Text) 
     lstResults.Items.Add("Cost: " & FormatCurrency(txtCost.Text)) 
     lstResults.Items.Add("Estimated life: " & txtLife.Text) 
     lstResults.Items.Add("Method of Depreciation: Double-Declining-Balance Method") 
     lstResults.Items.Add(" ") 
     doubleDecline(CInt(txtYear.Text), CInt(txtCost.Text), CInt(txtLife.Text)) 
    End Sub 


    Sub doubleDecline(year As Integer, cost As Integer, life As Integer) 
     Dim depreciation As Integer = cost * 0.5 
     Dim totalDepreciation As Integer = depreciation 
     While (cost > 0) 
      lstResults.Items.Add("Value at Beginning of " & year & ": " & vbTab & vbTab & FormatCurrency(cost)) 
      lstResults.Items.Add("Ammount of depreciation during " & year & ": " & vbTab & FormatCurrency(depreciation)) 
      lstResults.Items.Add("Total depreciation at the end of " & year & ": " & vbTab & FormatCurrency(totalDepreciation)) 
      lstResults.Items.Add(" ") 
      year += 1 
      cost -= depreciation 
      totalDepreciation += depreciation 
     End While 
    End Sub 

无论出于何种原因,折旧每年都保持不变,并且不每次减少50%,我不知道该做什么。任何帮助或方向表示赞赏!谢谢!

+1

您在计算中似乎没有使用“life”的值。 –

回答

1

您正在将您的折旧设置在您的While语句之外,因此它始终是起始费用的一半。尝试这样的事情,你需要弄清楚要如何停止你的while语句,因为你永远不会低于1,因为使用的是整数,我可能会改变你的成本,折旧和totalDepreciation一个小数,

Sub doubleDecline(year As Integer, cost As Integer, life As Integer) 
    Dim depreciation As Integer = cost * 0.5 
    Dim totalDepreciation As Integer = depreciation 
    While (life > 0) 
     lstResults.Items.Add("Value at Beginning of " & year & ": " & vbTab & vbTab & FormatCurrency(cost)) 
     lstResults.Items.Add("Ammount of depreciation during " & year & ": " & vbTab & FormatCurrency(depreciation)) 
     lstResults.Items.Add("Total depreciation at the end of " & year & ": " & vbTab & FormatCurrency(totalDepreciation)) 
     lstResults.Items.Add(" ") 
     year += 1 
     life -=1 
     cost -= depreciation 
     depreciation = cost * 0.5 'Note calculation of your depreciation here 
     totalDepreciation += depreciation 
    End While 
End Sub 

看看这个修改是否适合你。

Sub doubleDecline(year As Integer, cost As Double, life As Integer) 
    Dim depreciation As Double = cost * 0.5 
    Dim totalDepreciation As Double = depreciation 
    While (cost > 0) 
     lstResults.Items.Add("Value at Beginning of " & year & ": " & vbTab & vbTab & FormatCurrency(cost)) 
     lstResults.Items.Add("Ammount of depreciation during " & year & ": " & vbTab & FormatCurrency(depreciation)) 
     lstResults.Items.Add("Total depreciation at the end of " & year & ": " & vbTab & FormatCurrency(totalDepreciation)) 
     lstResults.Items.Add(" ") 
     year += 1 
     life -= 1 
     cost -= depreciation 
     cost = Math.Round(cost, 2) 
     depreciation = cost * 0.5 'Note calculation of your depreciation here 
     totalDepreciation += depreciation 
    End While 
    Console.ReadLine() 
End Sub 
+0

你也应该考虑到生活。 – varocarbas

+0

@varocarbas我知道,我只是指出他的错误,这就是为什么我说他应该确定他是如何停止循环的。 –

+0

你说得对,好点:它不仅要考虑到它的预期行为(不超过最大年数),还因为否则这个循环可能不会结束。 – varocarbas