I have an assignment to create a website that people can use to make dinner reservations. We are using Visual Basic code for the forms. It's supposed to keep running totals of each type of dinner. I'm having trouble getting the running totals to not reset to zero. I have them declared outside of the button click event. Not sure where I went wrong. Here's the code:
Option Strict On
Partial Class _Default
Inherits System.Web.UI.Page
Private Chicken_RT As Integer
Private Rib_RT As Integer
Private Veg_RT As Integer
Protected Sub SubmitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitButton.Click
'Variables
Dim DinnerPrice As Integer
Dim RadioSelect As Boolean = True
Dim Tickets As Integer
Dim DinnerType As String
'Parsing
Tickets = Integer.Parse(TicketTextBox.Text)
'Validation / Calculations
If TicketRangeValidator.IsValid And TicketValidator.IsValid Then
If ChickenRadio.Checked = True Then
DinnerPrice = Tickets * 15
Chicken_RT += Tickets
DinnerType = "Chicken"
ElseIf RibRadio.Checked = True Then
DinnerPrice = Tickets * 20
Rib_RT += Tickets
DinnerType = "Rib"
ElseIf VegetarianRadio.Checked = True Then
DinnerPrice = Tickets * 12
Veg_RT += Tickets
DinnerType = "Vegetarian"
Else
RadioErrorLabel.Text = ("Please select a dinner type")
RadioSelect = False
End If
'Display results
If RadioSelect = True Then
If OpenBarCheckBox.Checked = True Then
DinnerPrice += Tickets * 15
OpenBarLabel.Text = "Yes"
Else
OpenBarLabel.Text = "No"
End If
NumberDinnersLabel.Text = Tickets.ToString()
DinnerTypeLabel.Text = DinnerType
TotalCostLabel.Text = DinnerPrice.ToString("C")
TotalChickenLabel.Text = Chicken_RT.ToString()
TotalRibLabel.Text = Rib_RT.ToString()
TotalVegetarianLabel.Text = Veg_RT.ToString()
End If
End If
End Sub
End Class