折旧计算

时间:2013-08-31 17:38:28

标签: vb.net

我的表单应该让某人选择直线折旧和双倍折旧余额折旧。直线,我已经想通了,但由于某种原因我不能让Double-Decline工作。基本上,用户输入项目的年份,成本和估计寿命,程序会向他们显示该项目的年度折旧。

因此,如果该项目来自2013年,售价1000美元,预期寿命为4年,我希望输出看起来像: 2013年初的价值:1000美元 2013年折旧额:500美元(占成本的50%) 2013年底的折旧总额:500美元

2014年初的价值:500美元(成本 - 以前的折旧) 2014年的折旧额: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 个答案:

答案 0 :(得分: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