2012-02-01 14 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

助けてくれてありがとう! –

2

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

VB6のために、あなたは.AddItemを使用する必要があります。ここでは割り当てが何であるかにリンクし、見えるようになっているかのイメージがあります。

+0

私はあなたのコードを私の代わりに使用しましたが、リストボックスには何も印刷されません。 –

+0

私はドミトリーが正しいと思います。これについてはMSDN docoの例をご覧ください。 http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.aspxこの例では、(スペースに頼るのではなく)マルチカラムリストボックスをどのように設定し、どのように(ドミトリーが上で行ったように)項目を追加します。 –

関連する問題