I am creating a program that will allow a user to book seats in a theatre as a college project. It will feature a series of picture boxes that the user can click on to book a seat. The image in the picture box changes between the colour red and the colour green every time its pressed (if it is green, when it is clicked, it will become red etc.)
As for the function DetermineEnable, the value SeatNo represents the seat in the array enabled. This value is specific for each box (For seat A1, the seatno is 1). This value must remain the same, for the same box. The seatserial is just the name given to each picturebox (a1, a2, a3, a4, a5 etc).
I have only posted code for the first 5 seats, as this should give a general idea about what I'm asking.
What I'm asking is how can I "compact" all of the picturebox click events, So I only have to call the function "DetermineEnable" once or twice rather than 50+ times.
Many thanks!
' /// VISUAL AND INTERACTIVE DISPLAY
Sub DetermineEnable(ByVal SeatNo As Integer, ByVal SeatSerial As PictureBox)
If Enabled(SeatNo) = True Then
Enabled(SeatNo) = False
TotalCustomers = TotalCustomers - 1
ElseIf Enabled(SeatNo) = False Then
Enabled(SeatNo) = True
TotalCustomers = TotalCustomers + 1
End If
PictureLocation(SeatNo, SeatSerial)
UpdateEverything()
End Sub
Function PictureLocation(ByVal SeatNo As Integer, ByVal Picturebox As PictureBox) As String
If Enabled(SeatNo) = True Then
PictureLocation = "C:\Users\Wallace\Desktop\Theatre_Booking_System\enabled.png"
Else
PictureLocation = "C:\Users\Wallace\Desktop\Theatre_Booking_System\disabled.png"
End If
Picturebox.ImageLocation = PictureLocation
End Function
Private Sub a1_Click(sender As System.Object, e As System.EventArgs) Handles a1.Click
DetermineEnable(1, a1)
End Sub
Private Sub a2_Click(sender As System.Object, e As System.EventArgs) Handles a2.Click
DetermineEnable(2, a2)
End Sub
Private Sub a3_Click(sender As System.Object, e As System.EventArgs) Handles a3.Click
DetermineEnable(3, a3)
End Sub
Private Sub a4_Click(sender As System.Object, e As System.EventArgs) Handles a4.Click
DetermineEnable(4, a4)
End Sub
Private Sub a5_Click(sender As System.Object, e As System.EventArgs) Handles a5.Click
DetermineEnable(5, a5)
End Sub