2012-02-01 32 views
0

所以這裏是我在哪裏。我無法在我創建的名爲「depreciationListBox」的列表框上顯示任何內容,我一直在爲這個項目工作一段時間,而且我非常難過。任何人都可以幫助我的任何指針或解決方案將不勝感激。VB折舊

Private Sub displayButton_Click(ByVal sender As Object, _ 
    ByVal e As System.EventArgs) Handles displayButton.Click 

    Dim cost As Double 
    Dim life As Double = CDbl(lifeListBox.SelectedItem) 
    Dim period As Double 
    Dim nextPeriod As Double 
    Dim salvage As Double 
    Dim depreciation As Double 
    Dim isConvertedCost As Boolean 
    Dim isConvertedLife As Boolean 
    Dim isConvertedSalvage As Boolean 

    isConvertedCost = Double.TryParse(AssetTextBox.Text, cost) 
    isConvertedLife = Double.TryParse(lifeListBox.Text, life) 
    isConvertedSalvage = Double.TryParse(salvageTextBox.Text, salvage) 

    For nextPeriod = 1 To period Step 1 
    depreciation = Financial.DDB(cost, salvage, life, nextPeriod) 
    depreciationListBox.Text += nextPeriod.ToString & " " & _ 
     Convert.ToString(depreciation) _ 
     & ControlChars.NewLine 
    Next nextPeriod 

    If isConvertedCost AndAlso isConvertedLife _ 
     AndAlso isConvertedSalvage Then 
    depreciationListBox.Text = " Year Depreciation " 
    End If 
End Sub 

我哪裏出錯了?下面是分配就是一個鏈接,它應該是怎樣看的圖像:http://books.google.com/books?id=UAo8tAQRvGUC&pg=PT415&lpg=PT415&dq=sonheim+manufacturing&source=bl&ots=G74EzxAphD&sig=tS7s6EUUmgWrq6ZXphhDhDaBpsw&hl=en&sa=X&ei=KM8pT7mPA6qq2QWtq_ncAg&ved=0CEgQ6AEwBA#v=onepage&q=sonheim%20manufacturing&f=false

回答

1

在你的循環中,你從1循環到句點,但是你永遠不會初始化句點。 period的默認值爲0,這意味着循環永遠不會運行。

+0

感謝您的幫助! – 2012-02-02 09:22:56

2

使用depreciationListBox.Items.Add(nextPeriod.ToString & " " & Convert.ToString(depreciation))

對於VB6,你應該使用.AddItem。

+0

嗯,我用你的代碼代替我的東西,仍然沒有打印出列表框....沒有任何地方顯示。 – 2012-02-02 00:29:26

+0

我認爲德米特里是正確的。查看MSDN doco給出的例子, http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.aspx你可以在這個例子中看到他們如何設置多列列表框(而不是依賴空格)以及它們是如何然後添加項目(如德米特里所做的那樣)。 – 2012-02-02 04:07:16

相關問題