0
我有一個關於在Visual Basic中的任務的問題。問題是要求用戶設計一個Windows應用程序並編寫將根據需求文檔執行的代碼。對於這個問題的定價要求如下:對於季票,Box座位是2500美元,下層座位是1500美元。對於單場比賽門票,Box座位是55美元,下層座位是35美元,上層座位是25美元,而僅有Standing Room是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