2017-03-31 2 views
-2

Ich arbeite an einem Schulprojekt mit VIsual Studio 2015, die Aufgabe ist es, GUI "Commute Calculator" mit drei Optionen für das Transportmittel zu erstellen. Ich habe geschrieben, den Code gemäß den Anweisungen in meinem Lehrbuch, aber ich erhalte die folgende Fehlermeldung:Dezimal zu Integer Konvertierung Fehler

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

ich ein Neuling bin zu gegen, aber basierend auf dem Fehler ich das Problem glauben, ist mit, wie ich Variablen deklariert. Ich habe gegoogelt, wie man eine ganze Zahl in dezimal umwandelt, aber nichts gefunden, was funktioniert hat. Der Code ist langwierig, aber ich habe alles als eine FYI aufgenommen. Der Fehler ist in der privaten Sub-btnCommute und scheint mit drei privaten Funktionen verknüpft zu sein: CarFindCost, BusFindCost und TrainFindCost. Wie kann ich es beheben, so bekomme ich keine Fehler in der Variable IntLength in der privaten sub bthCommute?

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

Sie haben 215 Zeilen Code geschrieben. Sie erhalten Compiler Fehler in 1. Und es ist kein Fehler beim Konvertieren von Dezimal in Integer. – abatishchev

+3

Sie übergeben 3 Argumente ('intLength' ist der dritte) an eine Funktion, die nur 2 Argumente erwartet. – Ryan

+0

@abatishchev. Warum solltest du dich damit befassen, wenn du nichts hilfreiches zu sagen hast? Ich bin neu dazu und um Hilfe bittet, wäre ein bisschen Mitgefühl statt einer Kritik schön gewesen. Bitte zögern Sie nicht mich zu blockieren, wenn Stapelüberlauf diese Option hat. – lorac1969

Antwort

1

In:

Select Case intCommuteChoice ... End Select 

in jeder case; Rufen Sie die Funktion CarFindCost mit 3 Parametern auf, die Sie mit nur 2 deklariert haben.

+0

Hallo Roberto, danke, dass du mich in die richtige Richtung gelenkt hast. Es kann einschüchternd sein, mit Techies umzugehen, von denen du weißt, dass sie viel besser sind als du, also nochmals vielen Dank. – lorac1969

+0

@ lorac1969 Wenn dies Ihre Frage beantwortet, bitte ** upvote und akzeptieren ** diese Antwort. Wenn es Ihr Problem nicht gelöst hat, Sie es aber hilfreich fanden, ** upvote ** bitte die Antwort. – Yatrix

Verwandte Themen