0

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
4

1 に答える 1

0

デバッガーを使用して、cboTicketSelection.SelectedIndex()が期待される結果を返しているかどうかを確認します。毎回0を返すようです。

于 2012-11-28T21:11:52.483 に答える