user2270974
user2270974

Reputation: 1

Expected values do not display in ListBox

I have an Investment Return application which will take an invested amount of money and yield a return each year of 5% of the total and display the results, per year, in a ListBox. I am not getting any errors, but the GUI does not display the Investment yields in the listbox. Any suggestions would be appreciated. This is the code I have so far:

 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

Upvotes: 0

Views: 63

Answers (2)

Steve
Steve

Reputation: 216243

If lstBalances is a listbox then you need to add your calcs to the Items collection

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

As a side note: I really don't understand your calcs so I can't say if what you are doing is right or not, just trying to fix your programming trouble with listboxes.....

Upvotes: 2

Rowland Shaw
Rowland Shaw

Reputation: 38130

It appears that you're setting the text for the listbox on each iteration of the loop. From your description, it sounds like you want to be appending a value for each iteration, e.g. something like:

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

Upvotes: 0

Related Questions