为什么这个功能不能用于我的程序。 (Visual Basic)

时间:2011-02-24 18:36:35

标签: vb.net visual-studio-2008

我正在为一个班级项目做棒球课程。而且我几乎完成它,但它给了我一个语法错误。我无法弄清楚我做错了什么。我正在使用两个函数将不同类型棒球票的值返回到计算它们的按钮。

以下是说明 1.)用户选择是购买季票还是单票?

2.)用户根据他们是否选择了赛季单场比赛门票,输入所需的门票数量和座位类型。

3.)用户点击计算票据成本按钮以显示最终成本

4.。)用户单击“清除表单”按钮以清除响应

我无法弄清楚我做错了什么。我知道我正在做的事情是愚蠢的。

错误发生在btnCompute子例程中。 在SingleGameCost()和SeasonalCost()第114和118行

上使用语法错误
Public Class Form1
'Global Variables

Dim intTicketChoice As Integer
Dim seatType As Integer
Dim ticketNum As Integer








Private Sub cboTicketType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboTicketType.SelectedIndexChanged



    intTicketChoice = Me.cboTicketType.SelectedIndex
    Me.lstSeatType.Items.Clear()

    Select Case intTicketChoice

        Case 0
            SingleGame()

        Case 1
            Seasonal()


    End Select

    'Make Items visible

    Me.lblCostDisplay.Visible = True
    Me.lblSeats.Visible = True
    Me.lblTickets.Visible = True
    Me.lstSeatType.Visible = True
    Me.txtTicketNum.Visible = True
    Me.btnClear.Visible = True
    Me.btnCompute.Visible = True
    Me.txtTicketNum.Focus()

End Sub

Private Sub SingleGame()





    'Add List Items

    Me.lstSeatType.Items.Add("Box Seats $55")
    Me.lstSeatType.Items.Add("Lower Deck Seats $35")
    Me.lstSeatType.Items.Add("Upper Deck Seats $25")
    Me.lstSeatType.Items.Add("Standing Room Only $15")

    If lstSeatType.SelectedItem = "Box Seats $55" Then
        seatType = 0
    End If

    If lstSeatType.SelectedItem = "Lower Deck Seats $35" Then
        seatType = 1
    End If

    If lstSeatType.SelectedItem = "Upper Deck Seats $25" Then
        seatType = 2
    End If

    If lstSeatType.SelectedItem = "Standing Room Only $15" Then
        seatType = 3
    End If


End Sub



Private Sub Seasonal()





    'Add List Items
    Me.lstSeatType.Items.Add("Box Seats $2500")
    Me.lstSeatType.Items.Add("Lower Deck Seats $1500")


    'Price Items for Single Games
    If lstSeatType.SelectedItem = "Box Seats $2500" Then
        seatType = 4
    End If

    If lstSeatType.SelectedItem = "Lower Deck Seats $1500" Then
        seatType = 5
    End If


End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

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



    intTicketChoice = Me.cboTicketType.SelectedIndex

    If intTicketChoice = 0 Then
        SingleGameCost()
    End If

    If intTicketChoice = 1 Then
        SeasonalCost()

    End If


    'try and catch number textbox

    Try
        ticketNum = Convert.ToInt32(txtTicketNum.Text)
    Catch Exception As FormatException
        MsgBox("Number of tickets must be numeric")
        Return

    End Try

    'display cost of tickets

    Me.lblCostDisplay.Text = "The total cost of tickets purchased: " & totalCost.ToString("C")


End Sub

Private Function SingleGameCost(ByVal seatType As Integer, ByRef ticketNum As Integer, ByRef cost As Decimal) As Decimal
    Dim totalCost As Decimal


    ticketNum = Convert.ToInt32(Me.txtTicketNum.Text)

    'Price Items for Single Games

    If seatType = 0 Then
        cost = 55D
    End If


    If seatType = 1 Then
        cost = 35D
    End If


    If seatType = 2 Then
        cost = 25D
    End If

    If seatType = 3 Then
        cost = 15D
    End If

    totalCost = ticketNum * cost
    Return totalCost


End Function
Private Function SeasonalCost(ByVal seatType As Integer, ByRef ticketNum As Integer, ByRef cost As Decimal) As Decimal
    Dim totalCost As Decimal



    ticketNum = Convert.ToInt32(Me.txtTicketNum.Text)

    If seatType = 4 Then
        cost = 2500D
    End If

    If seatType = 5 Then
        cost = 1500D
    End If

    totalCost = cost * ticketNum
    Return totalCost



End Function

结束班

错误发生在这里

If intTicketChoice = 0 Then
        SingleGameCost()
    End If

    If intTicketChoice = 1 Then
        SeasonalCost()

    End If

使用singlegamecost()函数和seasonacost()函数

2 个答案:

答案 0 :(得分:3)

我很快就看了一眼,看来你被称为SingleGameCost()和 没有任何参数的SeasonalCost(),但你用一些函数定义了函数。

`Private Function SingleGameCost(ByVal seatType As Integer, ByRef ticketNum As Integer, ByRef cost As Decimal)`

你不应该提供论据吗?

 dim seat as integer = 1
 dim ticketNum as integer = 1
 dim cost as decimal = 12.00
 SingleGameCost(seat, ticketNum, cost)

答案 1 :(得分:0)

在我的脑海中,如果它是返回,将其更改为End Sub,因为这不是一个函数而是一个子函数。但我不知道我是否不知道哪一行给出错误。