title: Visual Basic, End of Statement Expected - Function
body: <p>I've been having issues trying to fix an "<strong>End of Statement Expected</strong>" 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. </p>
  
  <p>The exact position that I'm getting this error is;</p>
  
  <pre><code>While monthlyBal &gt; 0                                
        monthlyBal = Payments(tempBalances, monthlyRate)
  </code></pre>
  
  <p>I've added the rest of the code below.</p>
  
  <pre><code>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 " &amp; count &amp; ": ")
              System.Console.WriteLine(_SPACE &amp; "NAME: " &amp; cardNames(pos))
              System.Console.WriteLine(_SPACE &amp; "APRs: " &amp; cardAPRs(pos) &amp;"%")
              System.Console.WriteLine(_SPACE &amp; "BALANCE: " &amp; 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) &lt;&gt; swapNames(0) Then
                  If cardNames(pos) &lt;&gt; 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 &gt; 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
  </code></pre>
  
  <p>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 "<strong>Function Payments Statement</strong>" and the stuff inside the "<strong>Case 1 Statment</strong>". </p>