I've been working on this program for my VB.NET class and everything is working fine except for populating the combobox with the array. The problem is in initialized the array, I think. But when I change that, it says it's wrong. If someone could please take a look and see if you can spot where I'm messing up, I'd really appreciate it!
CODE
' Declare Variables
Dim arrayInterestTerm(2, 2) As Array ' Instantiate interest term array
Dim dblLoanAmount As Double ' Variable for Loan Amount
Dim dblInterestRate As Double ' Variable for Interest Rate
Dim intTerm As Integer ' Variable for Loan Term
Dim intTermResult As Integer
Dim dblInterestResult As Double
Dim decMonthlyPayment As Decimal ' Variable for Monthly Payment
Private Sub SunniVBMortgageCalculator2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Loads combobox with interest and term array values
Me.ClientSize = New System.Drawing.Size(250, 230) ' Set application window size
Me.txtLoanAmount.Text = "" ' Resets Loan Amount Text Box to Empty String
Me.txtLoanAmount.Focus() ' Sets focus to Loan Amount Text Box
Me.dgv.Hide() ' Hide Data Grid View
Try
Me.buildInterestTermArray() 'populate interest term array
Catch ex As Exception
MessageBox.Show("Error building interest option list, please exit and re-open the application.")
End Try
Try
For x As Integer = 0 To Me.arrayInterestTerm.GetUpperBound(x) 'add array to comboBox excluding price information
Me.comboInterestTerm.Items.Add(Me.arrayInterestTerm(x, 0))
Next x
Catch ex As Exception 'if loop fails, clear list and add items manually
Me.comboInterestTerm.Items.Clear()
Me.comboInterestTerm.Items.Add(Me.arrayInterestTerm(0, 0))
Me.comboInterestTerm.Items.Add(Me.arrayInterestTerm(1, 0))
Me.comboInterestTerm.Items.Add(Me.arrayInterestTerm(2, 0))
End Try
Me.comboInterestTerm.Text = Me.comboInterestTerm.Items.Item(0) 'set default selected item to item 0
Me.txtLoanAmount.Focus()
End Sub
Private Sub buildInterestTermArray()
' Builds room choice arrays
Me.arrayInterestTerm.SetValue("7", 0, 0)
Me.arrayInterestTerm.SetValue("years @", 0, 1)
Me.arrayInterestTerm.SetValue("5.35", 0, 2)
Me.arrayInterestTerm.SetValue("15", 1, 0)
Me.arrayInterestTerm.SetValue("years @", 1, 1)
Me.arrayInterestTerm.SetValue("5.50", 1, 2)
Me.arrayInterestTerm.SetValue("30", 2, 0)
Me.arrayInterestTerm.SetValue("years @", 2, 1)
Me.arrayInterestTerm.SetValue("5.75", 2, 2)
End Sub
You may be asking, why include the "years @" in the array for the combobox? Well I want the combobox to look like "7 years @ 5.35" etc when it is populated. But I need to use the "7" and "5.35" in calculations. Is there a better way to do this? I've been searching the web all night and haven't found a solution. I don't like to ask for help on message boards, but I feel I'm out of options. Thanks in advance for your time.