Vb.net 十进制到整数转换错误

Vb.net 十进制到整数转换错误,vb.net,Vb.net,我正在使用VIsual Studio 2015进行一个学校项目,任务是创建GUI“通勤计算器”,其中包含三种交通方式选项。我已经按照教科书中的说明编写了代码,但出现以下错误: BC30057将“专用函数CarFindCost(IntConvertChoice作为整数,intDays作为整数)作为十进制”的参数太多 我是vs的新手,但基于这个错误,我认为问题在于如何声明变量。我在谷歌上搜索了如何将整数转换成十进制,但没有找到任何有效的方法。代码很长,但我将其全部作为参考。该错误位于专用子btnCo

我正在使用VIsual Studio 2015进行一个学校项目,任务是创建GUI“通勤计算器”,其中包含三种交通方式选项。我已经按照教科书中的说明编写了代码,但出现以下错误:

BC30057将“专用函数CarFindCost(IntConvertChoice作为整数,intDays作为整数)作为十进制”的参数太多

我是vs的新手,但基于这个错误,我认为问题在于如何声明变量。我在谷歌上搜索了如何将整数转换成十进制,但没有找到任何有效的方法。代码很长,但我将其全部作为参考。该错误位于专用子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
选项严格打开
公共类frmCommuteCalc
将选定项设置为整数
Dim strSelectedMode As String=“”
Private _strgs为整数
Private\u strMiles As String=“输入往返行程的总英里数:”
私用汽油每加仑双倍=2.15
Private _strdaily标记为十进制=10
私人停车位(十进制)
专用_strMonthlyUpkeep,十进制=112
Private _strrtbusfareas String=“往返巴士票价为”
Private\u strrtRainfare As String=“往返火车票价为”
Private _strdaysas String=“输入每月工作天数:”
私家车票价为整数
私有子frmCommuteCalc_Load(发送方作为对象,e作为事件参数)处理MyBase.Load
线程。线程。睡眠(5000)
端接头
私有子cboCommuteMethod\u SelectedIndexChanged(发送方作为对象,e作为事件参数)处理cboCommuteMethod.SelectedIndexChanged
将选定项设置为整数
IntConvertChoice=cboCommuteMethod.SelectedIndex()
lstcurrent.Items.Clear()
选择案例和选择
案例0
汽车()
案例1
列车()
案例2
巴士()
结束选择
lblDays.Visible=True
lblMiles.Visible=True
lblLength.Visible=真
txtDays.Visible=True
'txtMonthlyTotal.Visible=True
端接头
私有子btnCompute\u单击(发送方作为对象,e作为事件参数)处理btnCompute。单击
将选定项设置为整数
Dim intDaysPerMonth为整数
以十进制表示的总成本
Dim intLength作为整数=0
Dim strSelectedMode As String=“”
Dim blnNumberInDaysIsValid为布尔值=False
Dim BLNCOMMUTEMETHO被选为布尔值=False
blnNumberInDaysIsValid=validateEnumberindays()
IntConvertChoice=ValidateCommuteSelection(BLNComMuteMethodDisselected,strSelectedMode)
如果(blnnumberindays有效且blnCommuteMethodIsSelected),则
intDaysPerMonth=Convert.ToInt32(txtDays.Text)
IntConvertChoice=cboCommuteMethod.SelectedIndex()
选择案例和选择
案例0
decTotalCost=CarFindCost(IntConversionChoice、intDaysPerMonth、intLength)
案例1
decTotalCost=BusFindCost(IntConversionChoice、intDaysPerMonth、intLength)
案例2
decTotalCost=TrainFindCost(IntConversionChoice、intDaysPerMonth、intLength)
结束选择
如果结束
端接头
私有函数intLength()作为对象
抛出新的NotImplementedException()
端函数
函数计算通勤成本(ByVal decMiles为十进制,ByVal Deccallons为十进制)为十进制
作为十进制数的Dim decillage
十进制=十进制英里/十进制加仑
回差
端函数
私家车()
lstcurtive.Items.Add(\u strMiles)
l通勤项目添加(_strmiles每加仑)
lstCommunion.Items.Add(_stdays)
lstCommunion.Items.Add(\u strMonthlyParking)
lstComment.Items.Add(\u strMonthlyUpkeep)
端接头
私家小巴()
1.通勤项目。添加(\u strRTBusFare)
lstCommunion.Items.Add(_stdays)
端接头
私家车()
lstCommunion.Items.Add(_stdays)
lstcurvet.Items.Add(\u strrtRainfare)
端接头
私有函数validateEnumberindays()作为布尔值
整数形式的整数
Dim blnValidityCheck为布尔值=假
Dim strNumberInDaysMessage As String=“请输入每月通勤天数”
Dim strMessageBoxTitle为String=“Error”
尝试
intDays=Convert.ToInt32(txtDays.Text)
如果intDays>=1且intDaysIn:


在每种情况下
;使用3个参数调用函数
CarFindCost
,您仅使用2个参数声明。

您已经发布了215行代码。您在1中遇到编译器错误。将十进制转换为整数并不是一个错误。您正在将3个参数(
intLength
是第三个)传递给一个只需要2个参数的函数。@abatishchev。如果你没有什么有用的话,为什么还要费心评论呢。我对这一点还不熟悉,如果我请求帮助,一点同情心就好了,而不是批评。如果堆栈溢出有此选项,请随时阻止我。对于第一个问题,我很抱歉您会遇到不愉快的评论。另一方面,我看你没有读到你收到的编译器错误,也没有试图让你的问题可读。@lorac1969他们是建设性的和有用的评论。阅读网站的规则,遵守它们,一切都会顺利进行。只张贴相关代码。如果你没有做出努力,你会被召唤出来的。你好,罗伯托,非常感谢你为我指明了正确的方向。与你知道在这方面比你强得多的技术人员打交道可能会让人感到害怕,所以再次感谢。@lorac1969如果这回答了你的问题,
Select Case intCommuteChoice ... End Select