James Owen
James Owen

Reputation: 41

Visual Basic, End of Statement Expected - Function

I've been having issues trying to fix an "End of Statement Expected" Error for this program I've been working on. Everything else seems to work fine until I've started working with the Function Statement that I called Payments. In this function I'm trying to calculate the monthlyBal for every month.

The exact position that I'm getting this error is;

While monthlyBal > 0                                
      monthlyBal = Payments(tempBalances, monthlyRate)

I've added the rest of the code below.

Module CreditCardCalculator

    Sub DisplayCreditCards(ByVal cardNames() As String, ByVal cardAPRs() As Double, ByVal cardBalances() As Double)
        Const _SPACE As String = "     "
        Dim count As Integer = 1

        System.Console.WriteLine("The Order of Credit Cards To Pay Off")
        System.Console.WriteLine("------------------------------------")
        For pos = 0 To cardNames.Length - 1
            System.Console.WriteLine("Credit Card " & count & ": ")
            System.Console.WriteLine(_SPACE & "NAME: " & cardNames(pos))
            System.Console.WriteLine(_SPACE & "APRs: " & cardAPRs(pos) &"%")
            System.Console.WriteLine(_SPACE & "BALANCE: " & cardBalances(pos))
            System.Console.WriteLine()
            count = count + 1
        Next
    End Sub

    Sub OrderofCreditCards(ByRef cardNames() As String, ByRef cardAPRs() As Double, ByRef cardBalances() As Double, ByVal SIZE as Integer)  
        Dim firstInput As String
        Dim secondInput As String
        Dim swapNames(SIZE) As String
        Dim swapAPRs(SIZE) As Double
        Dim swapBalances(SIZE) As Double

        System.Console.WriteLine("Which Credit Card would you like to payoff first?")
        firstInput = Console.ReadLine()
        For pos = 0 To cardNames.Length - 1
            If firstInput = cardNames(pos) Then
                swapNames(0) = cardNames(pos) 
                swapAPRs(0) = cardAPRs(pos) 
                swapBalances(0) = cardBalances(pos)
                Exit For
            End If
        Next

        System.Console.WriteLine("Which Credit Card would you like to payoff second?")
        secondInput = Console.ReadLine()
        For pos = 0 To cardNames.Length - 1
            If secondInput = cardNames(pos) Then
                swapNames(1) = cardNames(pos) 
                swapAPRs(1) = cardAPRs(pos) 
                swapBalances(1) = cardBalances(pos)
                Exit For
            End If
        Next
        For pos = 0 To cardNames.Length - 1
            If cardNames(pos) <> swapNames(0) Then
                If cardNames(pos) <> swapNames(1) Then
                    swapNames(2) = cardNames(pos) 
                    swapAPRs(2) = cardAPRs(pos) 
                    swapBalances(2) = cardBalances(pos)
                    Exit For
                End If
            End If
        Next

        cardNames = swapNames
        cardAPRs = swapAPRs
        cardBalances = swapBalances         
    End Sub

    Sub DisplayMenu()
        System.Console.WriteLine("CREDIT CARD CALCULATOR MENU")
        System.Console.WriteLine("===========================")
        System.Console.WriteLine("OPTION 1. Display Total Number Of Payments Required To Pay Off Each 

Card. ")
        System.Console.WriteLine()
        System.Console.WriteLine("OPTION 2. Display The Number Of Years, Or Months To Pay Off Each Card. 

")
        System.Console.WriteLine()
        System.Console.WriteLine("OPTION 3. Display The Balance To Payoff Each Card and Total Amount To 

Payoff All Cards Combined. ")
        System.Console.WriteLine()
        System.Console.WriteLine("OPTION 4. Exit The Program. ")
        System.Console.WriteLine()
        System.Console.WriteLine

("=============================================================================")
        System.Console.WriteLine("Instructions: Type The Number That Is Next To The Option You Want To 

Execute. ")
    End Sub

    Function Payments(ByVal tempBalances As Double, ByVal monthlyRate As Double) As Double
        Const ISSUECHARGE As Integer = 3
        Dim avgMonthlyBal As Double 
        Dim interest As Double
        Dim minimumPayment As Double

        avgMonthlyBal = tempBalances
        interest = monthlyRate
        avgMonthlyBal = avgMonthlyBal + interest
        minimumPayment = avgMonthlyBal * ISSUECHARGE
        avgMonthlyBal = avgMonthlyBal - minimumPayment
        Return avgMonthlyBal
    End Function

    Sub Main()
        Const MAX_SIZE AS Integer = 2
        Const BILLPERIOD As Integer = 30
        Const MONTHSINYEAR As Integer = 12
        Dim creditCards(MAX_SIZE) As String
            creditCards(0) = "Discover"
            creditCards(1) = "Visa"
            creditCards(2) = "Master Card"
        Dim creditCardAPRs(MAX_SIZE) As Double
            creditCardAPRs(0) = 12.99
            creditCardAPRs(1) = 7.5
            creditCardAPRs(2) = 18.9
        Dim creditCardBalances(MAX_SIZE) As Double
            creditCardBalances(0) = 300
            creditCardBalances(1) = 400
            creditCardBalances(2) = 500
        Dim myInput As String
        Dim optionNum As String
        Dim tempBalances As Double
        Dim monthlyRate As Double
        Dim numberofDays As Integer
        Dim monthlyBal As Double


        DisplayCreditCards(creditCards, creditCardAPRs, creditCardBalances)

        System.Console.WriteLine("Would you like to adjust the order of the Credit Card?")
        System.Console.WriteLine()
        System.Console.WriteLine("If Yes, type 'Y' --------------------- If No, type 'N'")

        myInput = Console.ReadLine()

        If myInput = "Y" Then
            OrderofCreditCards(creditCards, creditCardAPRs, creditCardBalances, MAX_SIZE)
        End If

        System.Console.WriteLine()
        Console.Clear()
        DisplayCreditCards(creditCards, creditCardAPRs, creditCardBalances)
        System.Console.WriteLine()
        DisplayMenu()
        optionNum = Console.ReadLine()
        numberOfDays = 30

        Select Case optionNum
            Case "1"
                For pos = 0 To creditCards.Length - 1
                    tempBalances = creditCardBalances(pos) * numberOfDays / BILLPERIOD
                    monthlyRate = creditCardAPRs(pos) / MONTHSINYEAR
                    monthlyBal = creditCardBalances(pos)
                    While monthlyBal > 0                                

                        monthlyBal = Payments(tempBalances, monthlyRate)
                        System.Console.WriteLine(monthlyBal)
                    End While                   
                Next
            Case "2"
                System.Console.WriteLine("Case 2")
            Case "3"
                System.Console.WriteLine("Case 3")
            Case "4"
                System.Console.WriteLine("Exiting The Program... ")
                Console.Read()
            Case Else
                System.Console.WriteLine("Error: Not a valid option from the menu. ")
                System.Console.WriteLine("Exiting The Program... ")
        End Select
    End Sub
End Module

It's either something small and I haven't spotted it yet or, I'm not working with functions correctly since the compiler seems to point to it. Like, I said everything else seems to be working fine and compiled correctly, until I added the "Function Payments Statement" and the stuff inside the "Case 1 Statment".

Upvotes: 1

Views: 21742

Answers (4)

soniya mahadik
soniya mahadik

Reputation: 1

con.ConnectionString = "Data Source=ADMIN-PC\SQLEXPRESS;Initial Catalog=" BILLING SYSTEM";Integrated Security=True"

This Expression will have error BC30205 End of statement expected.

Upvotes: 0

Ahmad
Ahmad

Reputation: 12737

In VB, you can not split strings in multiple lines like this

'This will give an error
System.Console.WriteLine("OPTION 3. Display The Balance To  Amount To 

Payoff Each Card and Total Payoff All Cards Combined. ")

Even if you remove the blank line in the middle, this will also give you an error

'This will also give an error
System.Console.WriteLine("OPTION 3. Display The Balance To  Amount To 
Payoff Each Card and Total Payoff All Cards Combined. ")

Here is what you can do if you must break long lines of code in VB:

'This is acceptable
System.Console.WriteLine("OPTION 3. Display The Balance To  Amount To " & _
"Payoff Each Card and Total Payoff All Cards Combined. ")

Or alternatively, (if you must have blank lines in between your code) you can type it like this:

'This is also acceptable
System.Console.WriteLine("OPTION 3. Display The Balance To  Amount To " & _
"" & _
"Payoff Each Card and Total Payoff All Cards Combined. ")

Upvotes: 0

Idle_Mind
Idle_Mind

Reputation: 39152

Once I fixed DisplayMenu() it all compiled just fine:

Sub DisplayMenu()
    System.Console.WriteLine("CREDIT CARD CALCULATOR MENU")
    System.Console.WriteLine("===========================")
    System.Console.WriteLine("OPTION 1. Display Total Number Of Payments Required To Pay Off Each Card. ")
    System.Console.WriteLine()
    System.Console.WriteLine("OPTION 2. Display The Number Of Years, Or Months To Pay Off Each Card. ")
    System.Console.WriteLine()
    System.Console.WriteLine("OPTION 3. Display The Balance To Payoff Each Card and Total Amount To Payoff All Cards Combined. ")
    System.Console.WriteLine()
    System.Console.WriteLine("OPTION 4. Exit The Program. ")
    System.Console.WriteLine()
    System.Console.WriteLine("=============================================================================")
    System.Console.WriteLine("Instructions: Type The Number That Is Next To The Option You Want To Execute. ")
End Sub

Upvotes: 0

paxdiablo
paxdiablo

Reputation: 882726

One thing that seems a little suspicious is that you have a number of (apparently) spaces at the end of the while line. I'd start by getting rid of those and trying again.

It may be that there's some funny characters in there that just got pasted into Stack Overflow as spaces, and these may be causing grief to the compiler.

It's a long shot since you have a few other lines like that but it's the only strangeness I can see at or around that line.

Upvotes: 1

Related Questions