Reputation: 377
I'm doing a baseball program for a class project. And I almost have it complete, but it's giving me a syntax error. I can't figure out what i'm doing wrong. I'm using two functions to return a value for different type of baseball tickets to the button that calculates them.
Here are the instructions 1.)User selects whether to purchase season tickets or single-game tickets
2.) User enters the number of tickets needed and the type of seats based on whether they selected season single-game tickets.
3.) User clicks the Compute Ticket Cost Button to display final cost
4.) User clicks the Clear Form button to clear the response
I just can't figure out what I did wrong. I know it's something stupid that i'm doing.
the errors are happening inside the btnCompute sub routine. with syntax erros on SingleGameCost() and SeasonalCost() line 114 and 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
End Class
kthe error is happening here
If intTicketChoice = 0 Then
SingleGameCost()
End If
If intTicketChoice = 1 Then
SeasonalCost()
End If
with the singlegamecost() function and the seasonacost() function
Upvotes: 0
Views: 835
Reputation: 205
I just quickly looked over this, and it seems you're called SingleGameCost() and SeasonalCost() without any arguments, but you defined the function with some.
`Private Function SingleGameCost(ByVal seatType As Integer, ByRef ticketNum As Integer, ByRef cost As Decimal)`
Shouldn't you be supplying the arguments?
dim seat as integer = 1
dim ticketNum as integer = 1
dim cost as decimal = 12.00
SingleGameCost(seat, ticketNum, cost)
Upvotes: 3
Reputation: 6450
On top of my head, if it's the return , change it to End Sub since this is not a function but a sub. But I can't tell if I don't know which line gives the error.
Upvotes: 0