How to fix error: EXPECTED: END STATEMENT? frmframe is highlighted in this code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • paul kangethe

    #1

    How to fix error: EXPECTED: END STATEMENT? frmframe is highlighted in this code

    Code:
    Public Class frmMain
    
    Private Sub btnCalulate_Click(ByVal sender As System.Object, ByVal e As
    
    System.EventArgs) Handles btnCalulate.Click
    
    Try
    Dim LoanAmount As Double
    
    Dim Payment As DoubleDim
    InterestRate As Double
    
    Dim Interest As DoubleDim
    Principle As Double
    
    Dim Years As IntegerDim
    PaymentPeriods As Integer
    
    Dim LoanOptionSelection As Integer
    
     
    
    'setup loan options array with values
    
    Dim LoanOptions(3, 2) As Double
    
    LoanOptions(0, 0) = 7
    
    LoanOptions(0, 1) = 5.35
    
    LoanOptions(1, 0) = 15
    
    LoanOptions(1, 1) = 5.5
    
    LoanOptions(2, 0) = 30
    
    LoanOptions(2, 1) = 5.75
    
     
    
    'validate loan amount input
    
    If IsNumeric(txtLoanAmount.Text) = False Then
    MsgBox("Loan amount must be numeric. Please enter a validloan amount.")
    
    txtLoanAmount.Clear()
    
    txtLoanAmount.Focus()
    
    Exit Sub
    
    End If
    
     
    
    'set loan variables
    
    LoanAmount = txtLoanAmount.Text
    
     
    
    'set proper rate and years depending on option selected by user
    
    Select Case True
    Case optLoanOption1.Checked
    
    LoanOptionSelection = 0
    Case optLoanOption2.Checked
    
    LoanOptionSelection = 1
    Case optLoanOption3.Checked
    
    LoanOptionSelection = 2
    
    End Select
    
     
    
    'using array and loan option set the rate and years
    
    InterestRate = LoanOptions(LoanOptionSelection, 1)
    
    Years = LoanOptions(LoanOptionSelection, 0)
    
     
    
    'calulate total payment periods
    
    PaymentPeriods = Years * 12
    
     
    
    'if rate is in percent form convert to decimal
    
    If InterestRate > 1 Then InterestRate = InterestRate / 100
    
     
    
    'calculate monthly payment and return value
    
    Payment = (LoanAmount * Math.Pow((InterestRate / 12) + 1,
    
    (PaymentPeriods)) * InterestRate / 12) / (Math.Pow(InterestRate / 12 + 1,
    
    (PaymentPeriods)) - 1)
    
     
    
    'display calculated payment
    lblMonthlyPayment.Text = "Monthly Payment: " &
    
    FormatCurrency(Payment)
    
     
    
    'clear datagrid view control (remove all rows)
    
    dgvLoanDetails.Rows.Clear()
    
     
    
    'setup progress bar
    
    pbLoan.Minimum = 1
    
    pbLoan.Maximum = PaymentPeriods
    
    pbLoan.Value = 1
    
    pbLoan.Visible = True
    
     
    
    'loop the loan payment periods displaying loan details
    Dim i As Integer
    
    For i = 1 To PaymentPeriods
    
     
    
    'increase progress bar
    
    pbLoan.Value = i
    
     
    
    'set interest
    
    Interest = (LoanAmount * InterestRate) / 12
    
     
    
    'set loan amount
    
    LoanAmount = (LoanAmount - Payment) + Interest
    
     
    
    'set principle
    
    Principle = Payment - Interest
    
     
    
    'output loan details
    
    dgvLoanDetails.Rows.Add()
    dgvLoanDetails.Item("Month", i - 1).Value = idgvLoanDetails.Item("Payment", i - 1).Value =
    
    FormatCurrency(Payment)
    dgvLoanDetails.Item("Interest", i - 1).Value =
    
    FormatCurrency(Interest)
    dgvLoanDetails.Item("Principle", i - 1).Value =
    
    FormatCurrency(Principle)
    dgvLoanDetails.Item("LoanAmount", i - 1).Value =
    
    FormatCurrency(LoanAmount)
    
    Next
    
     
    
    'hide progress bar now that processing is completed
    pbLoan.Visible = False Catch ex As Exception
    
    MsgBox("Error: " & ex.Message.ToString())
    
    End Try
    
    End Sub
    
    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As
    
    System.EventArgs) Handles btnClear.Click
    
     
    
    'clear fields
    
    txtLoanAmount.Clear()
    
    optLoanOption1.Checked = True
    
    lblMonthlyPayment.Text = ""
    
    txtLoanAmount.Text = "200000"
    
    dgvLoanDetails.Rows.Clear()
    
    End Sub
    
    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As
    
    System.EventArgs) Handles btnExit.Click
    
     
    
    'end program
    
    End
    
    End Sub
    
    End Class
    I WOULD LIKE IT TO WORK IN EXCEL
    Last edited by Stewart Ross; Nov 12 '10, 01:18 PM.
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    If you want to write code for running in Excel you will need to use Visual Basic for Applications (VBA), not VB itself. Excel will not understand the VB code as you have written it.

    -Stewart

    Comment

    Working...