0

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

2 Answers 2

2

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.....

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.