I am working on an assignment with my friend. I asked for help on how to do the loop and he gave me the code for that part. SO I copied and pasted it into vb. It works for him but everytime I try to debug it I keep getting the sign "Null exception was unhandled". But its not just one one line. Fist it starts on the LstInvoice.items.clear() but if I delete that, it goes through all the lines. What is going on? I used the LstInvoice.items.clear() before on other assignments and never had this problem before. Here is my code:
Private Sub btnStraight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStraight.Click
        Dim Cost As Double
        Cost = txtCost.Text
        Dim Salvage_Value As Double
        Salvage_Value = 0
        Dim Life As Double
        Life = txtLife.Text
        Dim Depreciation As Double
        Depreciation = (Cost / Life)
        Dim c As Integer, i As Integer, x As Integer, y As Integer, z As Integer
        c = CInt(CDbl(txtYear.Text))
        i = CInt(txtLife.Text)
        x = CInt(txtCost.Text)
        y = CInt(CDbl(x) / i)
        z = x - y
        LstInvoice.items.clear()
        LstInvoice.Items.Add("Description: " & "" & txtDescription.Text)
        LstInvoice.Items.Add("Year of purchase: " & txtYear.Text)
        LstInvoice.Items.Add("Cost: " & FormatCurrency(txtCost.Text))
        LstInvoice.Items.Add("Estimated life:" & txtLife.Text)
        LstInvoice.Items.Add("Method of Depresciation: straight-line method")
        LstInvoice.Items.Add("")
        LstInvoice.Items.Add("Value beginning of " & c & ": " & FormatCurrency(CInt(txtCost.Text)))
        LstInvoice.Items.Add("Amount of depreciation accruing: " & c & ": " & FormatCurrency(y))
        LstInvoice.Items.Add("Total depreaciation at end of " & c & ": " & FormatCurrency(z))
        LstInvoice.Items.Add("")
        c = c + 1
        Do While (x > 0)
            y = CInt(CDbl(x) / i)
            z = x - y
            x = z
            LstInvoice.Items.Add("Value beginning of " & c & ": " & FormatCurrency(x))
            LstInvoice.Items.Add("Amount of depreciation accruing: " & c & ": " & FormatCurrency(y))
            LstInvoice.Items.Add("Total depreaciation at end of " & c & ": " & FormatCurrency(z))
            LstInvoice.Items.Add("")
            i = i - 1
            c = c + 1
        Loop
 
     
    