I need to creat a list of interest rates in a listbox for a user to select from.
ID: 3640101 • Letter: I
Question
I need to creat a list of interest rates in a listbox for a user to select from. The list will contain the starting interest rate, and four increasing rates based on a random increment. So the selection list will have five choices on the list. For example:Initial rate: 4, Interval 2-so the list could have 4,6,8,10, and 12 as choices.
So far I have come up with this:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim r As New Random
Dim i As New Random
Dim intcount As Integer
For intcount = 1 To 5
ListBox1.Items.Add(CStr(r.Next(6)) * i.Next(5))
Next
End Sub
I get 5 rates, but they are not increments..they are totally new random numbers each time.
Any advice?
Thanks.
Explanation / Answer
Looks to me like you are creating a new random number every time through your for loop. I would recommend creating your random "interest rate" and the "increment" values outside the loop. Once inside the loop, add the "interest rate" with the "increment" to give you the new value. Also, if you start to get the same number in ListBox1, you need to ensure that you are updating the number that you keep adding your "increment" variable to. Hope this helps!!
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.