VERSION 5.00 Begin VB.Form frmTheaterBoxOffice Caption = "Theater Box Office" ClientHeight = 4668 ClientLeft = 2592 ClientTop = 1812 ClientWidth = 7068 LinkTopic = "Form1" ScaleHeight = 4668 ScaleWidth = 7068 Begin VB.CommandButton cmdSeats Height = 492 Index = 40 Left = 5400 TabIndex = 55 Top = 1320 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 39 Left = 5880 TabIndex = 54 Top = 1320 Width = 492 End Begin VB.CommandButton cmdDone Caption = "Done" Height = 372 Left = 5400 TabIndex = 53 Top = 240 Width = 1092 End Begin VB.CommandButton cmdLoadSeats Caption = "Load Seats" Height = 372 Left = 1680 TabIndex = 2 Top = 600 Width = 1092 End Begin VB.CommandButton cmdInitialize Caption = "Initialize" Height = 372 Left = 2880 TabIndex = 3 Top = 600 Width = 1092 End Begin VB.TextBox txtShowName Height = 288 Left = 1680 TabIndex = 1 Top = 240 Width = 2292 End Begin VB.CommandButton cmdSeats Height = 492 Index = 50 Left = 600 TabIndex = 52 Top = 1320 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 49 Left = 1080 TabIndex = 51 Top = 1320 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 48 Left = 600 TabIndex = 50 Top = 1800 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 47 Left = 1080 TabIndex = 49 Top = 1800 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 46 Left = 600 TabIndex = 48 Top = 2280 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 45 Left = 1080 TabIndex = 47 Top = 2280 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 44 Left = 600 TabIndex = 46 Top = 2760 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 43 Left = 1080 TabIndex = 45 Top = 2760 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 42 Left = 600 TabIndex = 44 Top = 3240 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 41 Left = 1080 TabIndex = 43 Top = 3240 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 38 Left = 5400 TabIndex = 42 Top = 1800 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 37 Left = 5880 TabIndex = 41 Top = 1800 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 36 Left = 5400 TabIndex = 40 Top = 2280 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 35 Left = 5880 TabIndex = 39 Top = 2280 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 34 Left = 5400 TabIndex = 38 Top = 2760 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 33 Left = 5880 TabIndex = 37 Top = 2760 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 32 Left = 5400 TabIndex = 36 Top = 3240 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 31 Left = 5880 TabIndex = 35 Top = 3240 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 30 Left = 2040 TabIndex = 34 Top = 1320 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 29 Left = 2520 TabIndex = 33 Top = 1320 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 28 Left = 3000 TabIndex = 32 Top = 1320 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 27 Left = 3480 TabIndex = 31 Top = 1320 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 26 Left = 3960 TabIndex = 30 Top = 1320 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 25 Left = 4440 TabIndex = 29 Top = 1320 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 24 Left = 2040 TabIndex = 28 Top = 1800 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 23 Left = 2520 TabIndex = 27 Top = 1800 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 22 Left = 3000 TabIndex = 26 Top = 1800 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 21 Left = 3480 TabIndex = 25 Top = 1800 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 20 Left = 3960 TabIndex = 24 Top = 1800 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 19 Left = 4440 TabIndex = 23 Top = 1800 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 18 Left = 2040 TabIndex = 22 Top = 2280 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 17 Left = 2520 TabIndex = 21 Top = 2280 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 16 Left = 3000 TabIndex = 20 Top = 2280 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 15 Left = 3480 TabIndex = 19 Top = 2280 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 14 Left = 3960 TabIndex = 18 Top = 2280 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 13 Left = 4440 TabIndex = 17 Top = 2280 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 12 Left = 2040 TabIndex = 16 Top = 2760 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 11 Left = 2520 TabIndex = 15 Top = 2760 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 10 Left = 3000 TabIndex = 14 Top = 2760 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 9 Left = 3480 TabIndex = 13 Top = 2760 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 8 Left = 3960 TabIndex = 12 Top = 2760 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 7 Left = 4440 TabIndex = 11 Top = 2760 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 6 Left = 2040 TabIndex = 10 Top = 3240 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 5 Left = 2520 TabIndex = 9 Top = 3240 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 4 Left = 3000 TabIndex = 8 Top = 3240 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 3 Left = 3480 TabIndex = 7 Top = 3240 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 2 Left = 3960 TabIndex = 6 Top = 3240 Width = 492 End Begin VB.CommandButton cmdSeats Height = 492 Index = 1 Left = 4440 TabIndex = 4 Top = 3240 Width = 492 End Begin VB.Shape Shape1 BorderWidth = 2 Height = 612 Left = 600 Top = 3960 Width = 5772 End Begin VB.Label lblShowName Caption = "Enter show name:" Height = 252 Left = 240 TabIndex = 0 Top = 240 Width = 1332 End Begin VB.Label lblStage Alignment = 2 'Center Caption = "STAGE" BeginProperty Font Name = "MS Sans Serif" Size = 13.8 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 372 Left = 1200 TabIndex = 5 Top = 4080 Width = 4572 End End Attribute VB_Name = "frmTheaterBoxOffice" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False ' Chapter 12 Theater Box Office Case Study ' 3/99 Option Explicit Private Const strEmptySeat As String = "---" Private Const strReservedSeat As String = "R" Private Const intNumSeats As Integer = 50 Private Type SeatRecord blnReserved As Boolean strName As String * 15 curPrice As Currency End Type Private Sub cmdLoadSeats_Click() Dim udtTheaterSeat As SeatRecord Dim intShowFile As Integer, lngRecLength As Long Dim intSeatNum As Integer 'Open file intShowFile = FreeFile lngRecLength = LenB(udtTheaterSeat) Open txtShowName.Text For Random As #intShowFile Len = lngRecLength 'Read record and update seat button caption For intSeatNum = 1 To intNumSeats Get #intShowFile, intSeatNum, udtTheaterSeat Call UpdateSeatCaption(cmdSeats(intSeatNum), udtTheaterSeat.blnReserved) Next intSeatNum 'Close file Close #intShowFile End Sub Private Sub cmdInitialize_Click() Dim intSeatNum As Integer 'Initialize seats For intSeatNum = 1 To intNumSeats Call ReserveSeat(strEmptySeat, intSeatNum) Call UpdateSeatCaption(cmdSeats(intSeatNum), False) Next intSeatNum End Sub Private Sub cmdSeats_Click(Index As Integer) Dim strName As String If cmdSeats(Index).Caption = strEmptySeat Then strName = InputBox("Seat price is " & Format(SeatPrice(Index), "Currency") & _ vbCrLf & "Enter last name of reservation:", _ "Reserve a seat") If strName <> "" Then Call ReserveSeat(strName, Index) Call UpdateSeatCaption(cmdSeats(Index), True) End If Else MsgBox SeatName(Index) & vbCrLf & Format(SeatPrice(Index), "Currency") End If End Sub '******************************************************************** ' Writes a SeatRecord record to the file with the name ' entered by the user. ' ' pre: strName is the name of the reservation, ' intSeatNum is a valid theater seat number ' post: A seat reservation has been written to a file '******************************************************************** Sub ReserveSeat(ByVal strName As String, ByVal intSeatNum As Integer) Dim udtTheaterSeat As SeatRecord Dim intShowFile As Integer, lngRecLength As Long 'Open file intShowFile = FreeFile lngRecLength = LenB(udtTheaterSeat) Open txtShowName.Text For Random As #intShowFile Len = lngRecLength 'Write record If strName = strEmptySeat Then udtTheaterSeat.blnReserved = False Else udtTheaterSeat.blnReserved = True udtTheaterSeat.strName = strName udtTheaterSeat.curPrice = SeatPrice(intSeatNum) End If Put #intShowFile, intSeatNum, udtTheaterSeat 'Close file Close #intShowFile End Sub '************************************************************************** ' Changes the caption of cmdSeat button to reflect the seat status ' ' pre: cmdSeat is a seat command button, blnReserved is True ' if seat reserved, False otherwise ' post: cmdSeat Caption indicates either empty or reserved '************************************************************************** Sub UpdateSeatCaption(ByRef cmdSeat As Object, ByVal blnReserved As Boolean) If blnReserved Then cmdSeat.Caption = strReservedSeat Else cmdSeat.Caption = strEmptySeat End If End Sub '********************************************************** ' Returns the price of seat intSeatNum ' ' pre: intSeatNum is a valid seat ' post: The Price of intSeatNum seat returned '********************************************************** Function SeatPrice(ByVal intSeatNum As Integer) As Currency Const intCenterSeatsStart As Integer = 1 Const intCenterSeatsEnd As Integer = 30 Const curCenterSeatPrice As Currency = 20 Const curSideSeatPrice As Currency = 15 If intSeatNum >= intCenterSeatsStart And intSeatNum <= intCenterSeatsEnd Then SeatPrice = curCenterSeatPrice Else SeatPrice = curSideSeatPrice End If End Function '********************************************************** ' Returns the name of the seat reservation ' ' pre: intSeatNum is a valid reserved seat ' post: The reservation name of intSeatNum seat returned '********************************************************** Function SeatName(ByVal intSeatNum As Integer) As String Dim udtTheaterSeat As SeatRecord Dim intShowFile As Integer, lngRecLength As Long 'Open file intShowFile = FreeFile lngRecLength = LenB(udtTheaterSeat) Open txtShowName.Text For Random As #intShowFile Len = lngRecLength 'Read record and return strName Get #intShowFile, intSeatNum, udtTheaterSeat SeatName = udtTheaterSeat.strName 'Close file Close #intShowFile End Function Private Sub cmdDone_Click() Unload Me End Sub