Visual Basic,语句结束预期 - 功能

时间:2013-11-20 03:43:27

标签: vb.net function compiler-errors

我一直在尝试修复此项目的“语句结束预期”错误,我一直在努力。在我开始使用我称之为付款的功能声明之前,其他所有功能似乎都能正常工作。在这个函数中,我试图计算每个月的monthlyBal。

我收到此错误的确切位置是;

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

我已经添加了下面的其余代码。

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

它要么是小的,我还没有发现它,或者我没有正确使用函数,因为编译器似乎指向它。就像,我说其他一切似乎工作正常并且编译正确,直到我添加了“功能支付声明”和“案例1声明”中的内容。

4 个答案:

答案 0 :(得分:1)

似乎有点可疑的一件事是你在while行的末尾有许多(显然)空格。我首先要摆脱那些并再试一次。

可能那里有一些有趣的人物刚刚被粘贴到Stack Overflow作为空格,这些可能会让编译器感到悲伤。

这是一个很长的镜头,因为你有其他一些类似的线,但这是我在该线或周围可以看到的唯一的奇怪。

答案 1 :(得分:0)

一旦我修复了DisplayMenu(),它就编译得很好:

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

答案 2 :(得分:0)

在VB中,你不能像这样分割多行中的字符串

'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. ")

即使你删除了中间的空行,这也会给你一个错误

'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. ")

如果必须在VB中断开长行代码,可以执行以下操作:

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

或者,(如果您的代码之间必须有空行),您可以这样输入:

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

答案 3 :(得分:0)

con.ConnectionString =“数据源= ADMIN-PC \ SQLEXPRESS;初始目录=”结算系统“;集成安全性=真”

此表达式将出现错误BC30205预期结束语句。