2017-03-31 101 views
-2

我正在使用VIsual Studio 2015开展一个学校项目,其任务是创建具有三种交通模式选项的GUI“通勤计算器”。我写的代码如下的说明我的课本,但我得到以下错误:十进制整数转换错误

"BC30057 Too many arguments to 'Private Function CarFindCost(intCommuteChoice As Integer, intDays As Integer) As Decimal'."

我是一个新手,VS,但基于我相信这个问题是我如何声明的变量错误。我googled如何将一个整数转换为十进制,但没有发现任何工作。代码很长,但我把它全部作为参考。该错误位于private sub btnCommute中,似乎与三个私有函数相关联:CarFindCost,BusFindCost和TrainFindCost。我如何解决它,所以我不会在私人小组bthCommute中的变量intLength错误?

Option Strict On 

Public Class frmCommuteCalc 
    Dim intCommuteChoice As Integer 
    Dim strSelectedMode As String = "" 
    Private _strGas As Integer 
    Private _strMiles As String = "Enter the total miles for a round trip: " 
    Private _strMilesPerGallon As Double = 2.15 
    Private _strDailyParking As Decimal = 10 
    Private _strMonthlyParking As Decimal 
    Private _strMonthlyUpkeep As Decimal = 112 
    Private _strRTBusFare As String = "Round trip bus fare is " 
    Private _strRTTrainFare As String = "Round trip train fare is " 
    Private _StrDays As String = "Enter the number of days worked per month: " 
    Private _intTrainFare As Integer 


    Private Sub frmCommuteCalc_Load(sender As Object, e As EventArgs) Handles MyBase.Load 

     Threading.Thread.Sleep(5000) 

    End Sub 

    Private Sub cboCommuteMethod_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboCommuteMethod.SelectedIndexChanged 

     Dim intCommuteChoice As Integer 

     intCommuteChoice = cboCommuteMethod.SelectedIndex() 
     lstCommute.Items.Clear() 

     Select Case intCommuteChoice 
      Case 0 
       Car() 
      Case 1 
       Train() 
      Case 2 
       Bus() 
     End Select 

     lblDays.Visible = True 
     lblMiles.Visible = True 
     lblLength.Visible = True 
     txtDays.Visible = True 
     'txtMonthlyTotal.Visible = True 


    End Sub 

    Private Sub btnCompute_Click(sender As Object, e As EventArgs) Handles btnCompute.Click 

     Dim intCommuteChoice As Integer 
     Dim intDaysPerMonth As Integer 
     Dim decTotalCost As Decimal 
     Dim intLength As Integer = 0 
     Dim strSelectedMode As String = "" 
     Dim blnNumberInDaysIsValid As Boolean = False 
     Dim blnCommuteMethodIsSelected As Boolean = False 

     blnNumberInDaysIsValid = ValidateNumberInDays() 

     intCommuteChoice = ValidateCommuteSelection(blnCommuteMethodIsSelected, strSelectedMode) 

     If (blnNumberInDaysIsValid And blnCommuteMethodIsSelected) Then 
      intDaysPerMonth = Convert.ToInt32(txtDays.Text) 
      intCommuteChoice = cboCommuteMethod.SelectedIndex() 
      Select Case intCommuteChoice 
       Case 0 
        decTotalCost = CarFindCost(intCommuteChoice, intDaysPerMonth, intLength) 
       Case 1 
        decTotalCost = BusFindCost(intCommuteChoice, intDaysPerMonth, intLength) 
       Case 2 
        decTotalCost = TrainFindCost(intCommuteChoice, intDaysPerMonth, intLength) 
      End Select 

     End If 



    End Sub 

    Private Function intLength() As Object 
     Throw New NotImplementedException() 
    End Function 

    Function ComputeCommuteCost(ByVal decMiles As Decimal, ByVal decGallons As Decimal) As Decimal 

     Dim decMilage As Decimal 

     decMilage = decMiles/decGallons 
     Return decMilage 

    End Function 
    Private Sub Car() 

     lstCommute.Items.Add(_strMiles) 
     lstCommute.Items.Add(_strMilesPerGallon) 
     lstCommute.Items.Add(_StrDays) 
     lstCommute.Items.Add(_strMonthlyParking) 
     lstCommute.Items.Add(_strMonthlyUpkeep) 

    End Sub 

    Private Sub Bus() 

     lstCommute.Items.Add(_strRTBusFare) 
     lstCommute.Items.Add(_StrDays) 
    End Sub 

    Private Sub Train() 
     lstCommute.Items.Add(_StrDays) 
     lstCommute.Items.Add(_strRTTrainFare) 

    End Sub 
    Private Function ValidateNumberInDays() As Boolean 

     Dim intDays As Integer 
     Dim blnValidityCheck As Boolean = False 
     Dim strNumberInDaysMessage As String = "Please enter the No. of days per month you will be commuting " 
     Dim strMessageBoxTitle As String = "Error" 

     Try 
      intDays = Convert.ToInt32(txtDays.Text) 
      If intDays >= 1 And intDays <= 21 Then 
       blnValidityCheck = True 
      Else 
       MsgBox(strNumberInDaysMessage, , strMessageBoxTitle) 
       txtDays.Focus() 
       txtDays.Clear() 
      End If 
     Catch Exception As FormatException 
      MsgBox(strNumberInDaysMessage, , strMessageBoxTitle) 
      txtDays.Focus() 
      txtDays.Clear() 
     Catch Exception As OverflowException 
      MsgBox(strNumberInDaysMessage, , strMessageBoxTitle) 
      txtDays.Focus() 
      txtDays.Clear() 
     Catch Exception As SystemException 
      MsgBox(strNumberInDaysMessage, , strMessageBoxTitle) 
      txtDays.Focus() 
      txtDays.Clear() 
     End Try 

     Return blnValidityCheck 

    End Function 

    Private Function ValidateCommuteSelection(ByRef blnDays As Boolean, ByRef strDays As String) As Integer 
     Dim intCommuteChoice As Integer 

     Try 
      intCommuteChoice = Convert.ToInt32(lstCommute.SelectedIndex) 
      strDays = lstCommute.SelectedItem.ToString() 
      blnDays = True 
     Catch Exception As SystemException 
      MsgBox("Select a commute mode", , "Error") 
      blnDays = False 
     End Try 

     Return intCommuteChoice 

    End Function 

    Private Function CarFindCost(ByVal intCommuteChoice As Integer, ByVal intDays As Integer) As Decimal 
     Dim decDaysPerMonth As Decimal 
     Dim decMiles As Decimal 
     Dim decMilesPerGallon As Decimal = 2 
     Dim decGasTotal As Decimal 
     Dim decDailyParking As Decimal = 10 
     Dim decMonthlyParking As Decimal 
     Dim decMonthlyUpkeep As Decimal = 112 
     Dim decFinalCost As Decimal 
     Dim intLength As Integer = 0 

     decMiles = Convert.ToDecimal(txtMiles.Text) 
     decMilesPerGallon = Convert.ToDecimal(txtGallons.Text) 
     decGasTotal = decMilesPerGallon * decMiles 
     decMonthlyParking = Convert.ToDecimal(lblLength.Text) 
     decMonthlyParking = decDailyParking * decDaysPerMonth 
     decFinalCost = Convert.ToDecimal(lblLength.Text) 
     decFinalCost = decGasTotal + decMonthlyUpkeep + decMonthlyParking 

     Return decFinalCost 

    End Function 

    Private Function BusFindCost(ByVal intCommuteChoice As Integer, ByVal intDays As Integer) As Decimal 

     Dim intLength As Integer = 0 
     Dim decDaysPerMonth As Decimal 
     Dim decBusFarePerDay As Decimal = 4 
     Dim decFinalCost As Decimal 

     decBusFarePerDay = Convert.ToDecimal(txtMonthlyTotal) 
     decFinalCost = decBusFarePerDay * decDaysPerMonth 

     Return decFinalCost 

    End Function 

    Private Function TrainFindCost(ByVal intCommuteChoice As Integer, ByVal intDays As Integer) As Decimal 

     Dim intLength As Integer = 0 
     Dim decDaysPerMonth As Decimal 
     Dim decTrainFarePerDay As Decimal = 18 
     Dim decFinalCost As Decimal 

     decTrainFarePerDay = Convert.ToDecimal(txtMonthlyTotal) 
     decFinalCost = Convert.ToDecimal(txtMonthlyTotal) 
     decFinalCost = decDaysPerMonth * decTrainFarePerDay 

     Return decFinalCost 

    End Function 
End Class 
+3

您已发布215行代码。你得到的编译器错误是1.它不是一个将十进制转换为整数的错误。 – abatishchev

+3

您将3个参数('intLength'是第三个参数)传递给仅需要2个参数的函数。 – Ryan

+0

@abatishchev。如果你没有什么有用的话,为什么还要评论呢?我对此很陌生,并且寻求帮助,一点同情心就会很好,而不是批评。如果堆栈溢出有这个选项,请随时阻止我。 – lorac1969

回答

1

在:

在每个 case
Select Case intCommuteChoice ... End Select 

;具有3个参数的呼叫功能CarFindCost y您只声明了2个参数。

+0

嗨罗伯托,非常感谢你指点我在正确的方向。这可能会吓倒与你知道比这更好的技术人员,再次感谢。 – lorac1969

+0

@ lorac1969如果这回答了你的问题,请** upvote并接受**这个答案。如果它没有解决你的问题,但你发现它有帮助,请** upvote **答案。 – Yatrix