user3347022
user3347022

Reputation: 259

I am trying to populate drop boxes

Here is what I have so far to populate a couple drop down boxes in visual basic.

I may need global variables but I am not sure how to do that. I have been told to use Dim and the variable names of the drop boxes but I keep getting errors saying they are already friends within the form.

*This is a homework assignment, however I am not asking you to do the assignment but simply asking help with the problem I am having within the drop boxes. I don't expect you wonderful people to earn my grades for me! Thank you for any help!

Public Class Form1
    '// Mortgage Calculator Assignment 1.
    '// Can calculate payments on a given loan at a given rate for a given term.
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub
    '// Inputs rate starting at 3.25% through 6.75% at steps of 0.25% into the drop down box.
    Private Sub cbRate_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbRate.SelectedIndexChanged
        For i As Decimal = 3.25 To 6.75 Step 0.25
            cbRate.Items.Add(i & "%")
        Next
    End Sub
    '// Inputs term in years from 10 through 40 at steps of 5 year intervals into the drop down box.
    Private Sub cbTerm_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbTerm.SelectedIndexChanged
        For i As Integer = 10 To 40 Step 5
            cbTerm.Items.Add(i)
        Next
    End Sub

End Class

Upvotes: 0

Views: 51

Answers (1)

doctorlove
doctorlove

Reputation: 19317

You do not need global variables.

Try just populating the combo boxes in the form load:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
   '// Inputs rate starting at 3.25% through 6.75% at steps of 0.25%
   ' into the drop down          
    For i As Decimal = 3.25 To 6.75 Step 0.25
        cbRate.Items.Add(i & "%")
    Next

    '// Inputs term in years from 10 through 40 at steps of 5 year intervals
    ' into the drop down box.
    For i As Integer = 10 To 40 Step 5
        cbTerm.Items.Add(i)
    Next
End Sub

Edit: the combo boxes were declared (probably) for you when you added them to the form in the designer.

Upvotes: 2

Related Questions