2013-04-11 71 views
0

我有一個投資回報申請,它將花費投資金額並每年返回總收入的5%,並在ListBox中顯示每年的結果。我沒有收到任何錯誤,但GUI不顯示列表框中的投資收益率。任何建議,將不勝感激。這是我到目前爲止的代碼:預期值不會顯示在列表框中

Public Class Form1 

     Const Interest_Rate As Double = 0.05 

Private Sub btncmdCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncmdCalculate.Click 

    Dim num_years As Integer 
    Dim intCounter As Integer 
    Dim current_value As Double 
    Dim future_amount As Double 

    current_value = Val(txtcurrent_value.Text) 
     num_years = Val(txtnum_years.Text) 
    current_value = current_value * Interest_Rate * num_years & vbTab _ 
      'calculate amount 

    For intCounter = 1 To num_years 
     future_amount = current_value * (1 + Interest_Rate)^intCounter 

     lstBalances.Text = current_value * Math.Pow(1 + Interest_Rate, intCounter) & "" & _ vbTab & FormatCurrency(current_value)" 

    Next intCounter 
End Sub 

回答

0

看來您在循環的每次迭代中都設置了列表框的文本。從您的描述中,聽起來您想要爲每個迭代附加值,例如。是這樣的:

lstBalances.Text &= current_value * Math.Pow(1 + Interest_Rate, intCounter) & vbTab & FormatCurrency(current_value) & vbCrLf 
2

如果lstBalances是一個列表框,那麼你需要你的Calcs(計算)添加到項目集合

lstBalances.Items.Add(current_value * Math.Pow(1 + Interest_Rate, intCounter) & vbTab & _ 
         FormatCurrency(current_value)) 

作爲一個方面說明:我真的不明白你Calcs(計算)這樣我就可以」不要說你在做什麼是對的,只是試圖用列表框來解決你的編程問題.....