我有一个投资回报申请表,它将投入一笔资金,每年产生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 :(得分:2)
如果lstBalances是一个列表框,那么您需要将您的计算添加到Items集合
lstBalances.Items.Add(current_value * Math.Pow(1 + Interest_Rate, intCounter) & vbTab & _
FormatCurrency(current_value))
作为旁注:我真的不明白你的计算方法,所以我不能说你做的是不是正确,只是试图用列表框修复编程问题......
答案 1 :(得分:0)
您似乎在循环的每次迭代中设置列表框的文本。根据您的描述,您似乎希望为每次迭代附加值,例如类似的东西:
lstBalances.Text &= current_value * Math.Pow(1 + Interest_Rate, intCounter) & vbTab & FormatCurrency(current_value) & vbCrLf