You defined intTerm twice :
Dim intTerm As Integer
and :
For intTerm As Integer
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
source:
Private Sub btnCalc_Click( sender As Object, e As EventArgs) Handles btnCalc.Click
' Display the monthly mortgage payment.
Dim intPrincipal As Integer
Dim dblRate As Double
Dim dblPay As Double
Dim intTerm As Integer
Integer.TryParse(txtPrincipal.Text, intPrincipal)
Integer.TryParse(lstRates.SelectedItem.ToString, intTerm)
Double.TryParse(lstRates.SelectedItem.ToString, dblRate)
dblRate = dblRate / 100
lblPay.Text = String.Empty
For intTerm As Integer = 15 To 30 Step 5
dblPay = Financial.Pmt(dblRate / 12, intTerm * 12, intPrincipal)
lblPay.Text = lblPay.Text & intTerm.ToString & " years: " & dblPay.ToString("C2") &
ControlChars.NewLine
Next intTerm
End Sub
You defined intTerm twice :
Dim intTerm As Integer
and :
For intTerm As Integer
Using the code you originally posted, what happens if you
simply remove the "As Integer" in the For statement?
' Display the monthly mortgage payment.
Dim intPrincipal As Integer
Dim dblRate As Double
Dim dblPay As Double
Dim intTerm As Integer
Integer.TryParse(txtPrincipal.Text, intPrincipal)
Integer.TryParse(lstRates.SelectedItem.ToString, intTerm)
Double.TryParse(lstRates.SelectedItem.ToString, dblRate)
dblRate = dblRate / 100
lblPay.Text = String.Empty
'For intTerm As Integer = 15 To 30 Step 5
For intTerm = 15 To 30 Step 5
dblPay = Financial.Pmt(dblRate / 12, intTerm * 12, intPrincipal)
lblPay.Text = lblPay.Text & intTerm.ToString & " years: " & dblPay.ToString("C2") &
ControlChars.NewLine
Next intTerm
Hi @ethan hinze ,
If I rename one of the variables ...
You also need to rename the variables in the loop:
Dim intPrincipal As Integer
Dim dblRate As Double
Dim dblPay As Double
Dim intTerm As Integer
Integer.TryParse(txtPrincipal.Text, intPrincipal)
Integer.TryParse(lstRates.SelectedItem.ToString, intTerm)
Double.TryParse(lstRates.SelectedItem.ToString, dblRate)
dblRate = dblRate / 100
lblPay.Text = String.Empty
For intTerm1 As Integer = 15 To 30 Step 5
dblPay = Financial.Pmt(dblRate / 12, intTerm1 * 12, intPrincipal)
lblPay.Text = lblPay.Text & intTerm1.ToString & " years: " & dblPay.ToString("C2") &
ControlChars.NewLine
Next intTerm1
Hope it could be helpful.
Best Regards,
Xingyu Zhao
*
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.