我有一个关于 Visual Basic 作业的问题。问题是要求用户设计一个 Windows 应用程序并编写将根据需求文档执行的代码。该问题的定价要求如下:对于季票,包厢座位为 2500 美元,下层座位为 1500 美元。对于单场比赛门票,包厢座位为 55 美元,下层为 35 美元,上层为 25 美元,仅站立室为 15 美元。当我的程序运行时,它似乎只使用了 $55 或 $2500 的值,并且就像其他值不是实际选择一样。其他一切都有效。任何帮助将不胜感激。这是我的代码:
' Program Name: Baseball Tickets Selection
' Author: William Gambill
' Date: November 26, 2012
' Purpose: The Baseball Tickets Selection application determines the
' type of baseball tickets available and calculates the cost
' depending upon the seat chosen and number of seats.
Option Strict On
Public Class frmBaseballTicketSales
' Class Variables
Private _strBoxSeats As String = "Box Seats $55"
Private _strLowerDeck As String = "Lower Deck Seats $35"
Private _strUpperDeck As String = "Upper Deck Seats $25"
Private _strStdRmOnly As String = "Standing Room Only $15"
Private _strSeasnBoxSeats As String = "Box Seats $2500"
Private _strSeasnLowerDeck As String = "Lower Deck Seats $1500"
Private Sub cboTicketSelection_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboTicketSelection.SelectedIndexChanged
' This event handler allows the user to enter the ticket choice
' and then calls subprocedures to place the seat choices in the list.
Dim intTicketChoice As Integer
intTicketChoice = Me.cboTicketSelection.SelectedIndex
lstSeatType.Items.Clear()
Select Case intTicketChoice
Case 0
SingleTickets()
Case 1
SeasonTickets()
End Select
' Make items visible in the window
lblNumberOfTickets.Visible = True
txtNumberOfTickets.Visible = True
lblSeatType.Visible = True
lstSeatType.Visible = True
btnCalculate.Visible = True
btnClear.Visible = True
lblTotalTicketCost.Visible = True
lblFinalTotalCost.Visible = True
' Clear the labels
lblFinalTotalCost.Text = ""
' Set focus on number in tickets text box
txtNumberOfTickets.Clear()
txtNumberOfTickets.Focus()
End Sub
Private Sub SingleTickets()
' This procedure fills in the possible single game tickets
lstSeatType.Items.Add(_strBoxSeats)
lstSeatType.Items.Add(_strLowerDeck)
lstSeatType.Items.Add(_strUpperDeck)
lstSeatType.Items.Add(_strStdRmOnly)
End Sub
Private Sub SeasonTickets()
' This procedure fills in the possible season tickets
lstSeatType.Items.Add(_strSeasnBoxSeats)
lstSeatType.Items.Add(_strSeasnLowerDeck)
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
' This button event handler determines the cost of baseball tickets
' based on ticket type, seat type, and number of tickets bought.
' It displays the total cost of the tickets.
Dim intNumberOfTickets As Integer
Dim blnNumberOfTicketsIsValid As Boolean = False
Dim blnTypeIsSelected As Boolean = False
Dim intTypeChoice As Integer
Dim intTicketChoice As Integer
Dim decTotalCost As Decimal
' Call a function to ensure the number of tickets is valid
blnNumberOfTicketsIsValid = ValidateNumberOfTickets()
' If number of tickets and the type selection are valid, calculate the cost
If (blnNumberOfTicketsIsValid) Then
intNumberOfTickets = Convert.ToInt32(txtNumberOfTickets.Text)
intTicketChoice = Me.cboTicketSelection.SelectedIndex()
Select Case intTicketChoice
Case 0
decTotalCost = SingleFindCost(intTypeChoice, _
intNumberOfTickets)
Case 1
decTotalCost = SeasonFindCost(intTypeChoice, _
intNumberOfTickets)
End Select
' Display the cost of the tickets
lblFinalTotalCost.Text = decTotalCost.ToString("C")
End If
End Sub
Private Function ValidateNumberOfTickets() As Boolean
' This procedure validates the value entered for the number of tickets
Dim intTicketNumber As Integer
Dim blnValidityCheck As Boolean = False
Dim strNumberOfTicketsErrorMessage As String = _
"Please enter the number of tickets (1-99)"
Dim strMessageBoxTitle As String = "Error"
Try
intTicketNumber = Convert.ToInt32(txtNumberOfTickets.Text)
If intTicketNumber > 0 And intTicketNumber < 100 Then
blnValidityCheck = True
Else
MsgBox(strNumberOfTicketsErrorMessage, , strMessageBoxTitle)
txtNumberOfTickets.Focus()
txtNumberOfTickets.Clear()
End If
Catch Exception As FormatException
MsgBox(strNumberOfTicketsErrorMessage, , strMessageBoxTitle)
txtNumberOfTickets.Focus()
txtNumberOfTickets.Clear()
Catch Exception As OverflowException
MsgBox(strNumberOfTicketsErrorMessage, , strMessageBoxTitle)
txtNumberOfTickets.Focus()
txtNumberOfTickets.Clear()
Catch Exception As SystemException
MsgBox(strNumberOfTicketsErrorMessage, , strMessageBoxTitle)
txtNumberOfTickets.Focus()
txtNumberOfTickets.Clear()
End Try
Return blnValidityCheck
End Function
Private Function SingleFindCost(ByRef intTypeSelection As Integer, _
ByRef intNumberOfTickets As Integer) As Decimal
' This function calculates the cost of Single Game tickets
Dim decTypeCost As Decimal
Dim decFinalCost As Decimal
Dim decSingleBoxCost As Decimal = 55D
Dim decSingleLowerCost As Decimal = 35D
Dim decSingleUpperCost As Decimal = 25D
Dim decSingleStandCost As Decimal = 15D
Select Case intTypeSelection
Case 0
decTypeCost = decSingleBoxCost
Case 1
decTypeCost = decSingleLowerCost
Case 2
decTypeCost = decSingleUpperCost
Case 3
decTypeCost = decSingleStandCost
End Select
decFinalCost = decTypeCost * intNumberOfTickets
Return decFinalCost
End Function
Private Function SeasonFindCost(ByRef intTypeSelection As Integer, _
ByRef intNumberOfTickets As Integer) As Decimal
' This function calculates the cost of Season Tickets
Dim decTypeCost As Decimal
Dim decFinalCost As Decimal
Dim decSeasonBoxCost As Decimal = 2500D
Dim decSeasonLowerCost As Decimal = 1500D
Select Case intTypeSelection
Case 0
decTypeCost = decSeasonBoxCost
Case 1
decTypeCost = decSeasonLowerCost
End Select
decFinalCost = decTypeCost * intNumberOfTickets
Return decFinalCost
End Function
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
' This event handler clears the form and resets the form for
' reuse when the user clicks the Clear button.
cboTicketSelection.Text = "Select Ticket Type"
txtNumberOfTickets.Clear()
lstSeatType.Items.Clear()
lblFinalTotalCost.Text = ""
lblNumberOfTickets.Visible = False
txtNumberOfTickets.Visible = False
lblSeatType.Visible = False
lstSeatType.Visible = False
btnCalculate.Visible = False
btnClear.Visible = False
lblTotalTicketCost.Visible = False
lblFinalTotalCost.Visible = False
End Sub
Private Sub frmBaseballTicketSales_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Hold the splash screen for 5 seconds
Threading.Thread.Sleep(5000)
End Sub
End Class