Simpler Coding?
Is there a simpler, more efficient way to code the toppings section, while still maintaining checkboxes?I am trying to get away from themultiple If/ElseIf/Then statements, if possible.
Thanks!
Private Sub btnOrderTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOrderTotal.Click
Dim pizzaCost As Single = 0
' Base cost of pizza, based on size
If radSmall.Checked = True Then
pizzaCost += 12.99
ElseIf radMedium.Checked = True Then
pizzaCost += 14.99
ElseIf radLarge.Checked = True Then
pizzaCost += 16.99
Else
MessageBox.Show("Please choose a pizza size.")
End If
' Add on additional costs for toppings
Const sngTOPPING_CHARGE As Single = 0.25
If chkPepperoni.Checked = True Then
pizzaCost += sngTOPPING_CHARGE
End If
If chkBlkOlives.Checked = True Then
pizzaCost += sngTOPPING_CHARGE
End If
If chkSausage.Checked = True Then
pizzaCost += sngTOPPING_CHARGE
End If
If chkOnion.Checked = True Then
pizzaCost += sngTOPPING_CHARGE
End If
If chkGrnOlive.Checked = True Then
pizzaCost += sngTOPPING_CHARGE
End If
If chkGrnPepper.Checked = True Then
pizzaCost += sngTOPPING_CHARGE
End If
If chkCanBacon.Checked = True Then
pizzaCost += sngTOPPING_CHARGE
End If
If chkPineapple.Checked = True Then
pizzaCost += sngTOPPING_CHARGE
End If
If chkMushroom.Checked = True Then
pizzaCost += sngTOPPING_CHARGE
End If
If chkHamburger.Checked = True Then
pizzaCost += sngTOPPING_CHARGE
End If
' Total cost of pizza
lblTotal.Text = "Cost: " & FormatCurrency(pizzaCost).ToString
End Sub

