1

我的表格应该让某人在直线折旧和双倍余额折旧之间进行选择。直线,我已经弄清楚了,但由于某种原因,我无法让 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%,我不知道该怎么办。任何帮助或方向表示赞赏!谢谢!

4

1 回答 1

1

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

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
于 2013-08-31T18:03:51.933 回答