2012-11-28 6 views
0

Visual Basic에서 배정 관련 질문이 있습니다. 문제는 사용자에게 Windows 응용 프로그램을 설계하고 요구 사항 문서에 따라 실행될 코드를 작성하라고 요청하는 것입니다. 문제의 가격 요구 사항은 다음과 같습니다. 시즌 티켓의 경우 Box 석은 2500 달러이고 하단 석은 $ 1500입니다. 싱글 게임 티켓의 경우 Box 좌석은 $ 55, Lower 갑판 $ 35, Upper 갑판 $ 25, Standing Room Only $ 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 

답변

0

() 예상 된 결과를 반환 내가 cboTicketSelection.SelectedIndex 여부를 확인하기 위해 디버거를 사용합니다 : 여기 내 코드입니다. 매번 0을 반환합니다 나타납니다.

관련 문제