Visual Basic, End of-Anweisung Erwartet - Funktion

Ich habe Probleme versuchen zu beheben einem "Ende der Anweisung Erwartet" Fehler für dieses Programm, das ich gearbeitet habe. Alles andere scheint zu funktionieren gut, bis ich angefangen habe, arbeiten mit der Function-Anweisung, die ich rief Zahlungen. In dieser Funktion versuche ich zu berechnen, die monthlyBal für jeden Monat.

Die genaue position, die ich bin immer dieser Fehler ist;

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

Habe ich den rest des Codes unten.

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

Entweder ist es etwas klein und ich habe nicht getupft es doch oder, ich bin nicht mit Funktionen arbeiten korrekt, da der compiler scheint auf ihn verweisen. Wie ich sagte, alles andere scheint einwandfrei zu funktionieren und korrekt compiliert, bis ich fügte hinzu, die "Funktion Zahlungen Anweisung" und die Sachen, die im "Fall 1 Statment".

InformationsquelleAutor James Owen | 2013-11-20
Schreibe einen Kommentar