I have created a simply Pizza program (for a summer project not education related) that uses check boxes to determine what the customer wants. Basically a simple pizza ordering program. I was wondering as I have used the If statement over and other again for different parameters and variables, is it possible to use multiply arrays to simply the VB Code...
I was advised to use Constructors in VB.Net, but have no current experience, could you help? Or is there a more simpler way to go about creating this program...or a better way of programing? What about decreasing the repetition in the code?
Option Strict On
Public Class Form1
Dim CurrentBalance As String
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Dim SmallPizza As String
SmallPizza = "5"
CurrentBalance = Label4.Text
If CheckBox1.Checked Then
ListBox1.Items.Add("Small Pizza")
Label4.Text = CStr(Val(CurrentBalance) + Val(SmallPizza))
Else
ListBox1.Items.Remove("Small Pizza")
Label4.Text = CStr(Val(CurrentBalance) - Val(SmallPizza))
End If
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
Dim MediumPizza As String
MediumPizza = "7"
CurrentBalance = Label4.Text
If CheckBox2.Checked Then
ListBox1.Items.Add("Medium Pizza")
Label4.Text = CStr(Val(CurrentBalance) + Val(MediumPizza))
Else
ListBox1.Items.Remove("Medium Pizza")
Label4.Text = CStr(Val(CurrentBalance) - Val(MediumPizza))
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CurrentBalance = Label4.Text
MessageBox("Total cost: £" & CurrentBalance)
End Sub
Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
Dim LargePizza As String
LargePizza = "9"
CurrentBalance = Label4.Text
If CheckBox3.Checked Then
ListBox1.Items.Add("Large Pizza")
Label4.Text = CStr(Val(CurrentBalance) + Val(LargePizza))
Else
ListBox1.Items.Remove("Large Pizza")
Label4.Text = CStr(Val(CurrentBalance) - Val(LargePizza))
End If
End Sub
Private Sub CheckBox4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox4.CheckedChanged
Dim ExtraLargePizza As String
ExtraLargePizza = "7"
CurrentBalance = Label4.Text
If CheckBox4.Checked Then
ListBox1.Items.Add("Extra Large Pizza")
Label4.Text = CStr(Val(CurrentBalance) + Val(ExtraLargePizza))
Else
ListBox1.Items.Remove("Extra Large Pizza")
Label4.Text = CStr(Val(CurrentBalance) - Val(ExtraLargePizza))
End If
End Sub
Private Sub CheckBox5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox5.CheckedChanged
Dim Ham As String
Ham = "1"
CurrentBalance = Label4.Text
If CheckBox5.Checked Then
ListBox1.Items.Add("Ham")
Label4.Text = CStr(Val(CurrentBalance) + Val(Ham))
Else
ListBox1.Items.Remove("Ham")
Label4.Text = CStr(Val(CurrentBalance) - Val(Ham))
End If
End Sub
Private Sub CheckBox6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox6.CheckedChanged
Dim Pineapple As String
Pineapple = "1"
CurrentBalance = Label4.Text
If CheckBox6.Checked Then
ListBox1.Items.Add("Pineapple")
Label4.Text = CStr(Val(CurrentBalance) + Val(Pineapple))
Else
ListBox1.Items.Remove("Pineapple")
Label4.Text = CStr(Val(CurrentBalance) - Val(Pineapple))
End If
End Sub
Private Sub CheckBox7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox7.CheckedChanged
Dim Bananna As String
Bananna = "1"
CurrentBalance = Label4.Text
If CheckBox7.Checked Then
ListBox1.Items.Add("Bananna")
Label4.Text = CStr(Val(CurrentBalance) + Val(Bananna))
Else
ListBox1.Items.Remove("Bananna")
Label4.Text = CStr(Val(CurrentBalance) - Val(Bananna))
End If
End Sub
Private Sub CheckBox8_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox8.CheckedChanged
Dim Meat As String
Meat = "1"
CurrentBalance = Label4.Text
If CheckBox8.Checked Then
ListBox1.Items.Add("Meat")
Label4.Text = CStr(Val(CurrentBalance) + Val(Meat))
Else
ListBox1.Items.Remove("Meat")
Label4.Text = CStr(Val(CurrentBalance) - Val(Meat))
End If
End Sub
Private Sub CheckBox9_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox9.CheckedChanged
Dim ExtraCheese As String
ExtraCheese = "1"
CurrentBalance = Label4.Text
If CheckBox9.Checked Then
ListBox1.Items.Add("Extra Cheese")
Label4.Text = CStr(Val(CurrentBalance) + Val(ExtraCheese))
Else
ListBox1.Items.Remove("Extra Cheese")
Label4.Text = CStr(Val(CurrentBalance) - Val(ExtraCheese))
End If
End Sub
Private Sub CheckBox10_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox10.CheckedChanged
Dim Pepperoni As String
Pepperoni = "1"
CurrentBalance = Label4.Text
If CheckBox10.Checked Then
ListBox1.Items.Add("Pepperoni")
Label4.Text = CStr(Val(CurrentBalance) + Val(Pepperoni))
Else
ListBox1.Items.Remove("Pepperoni")
Label4.Text = CStr(Val(CurrentBalance) - Val(Pepperoni))
End If
End Sub
Private Sub CheckBox11_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox11.CheckedChanged
Dim Special As String
Special = "1"
CurrentBalance = Label4.Text
If CheckBox11.Checked Then
ListBox1.Items.Add("Special")
Label4.Text = CStr(Val(CurrentBalance) + Val(Special))
Else
ListBox1.Items.Remove("Special")
Label4.Text = CStr(Val(CurrentBalance) - Val(Special))
End If
End Sub
Private Sub CheckBox12_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox12.CheckedChanged
Dim Pickup As String
Pickup = "1"
CurrentBalance = Label4.Text
If CheckBox12.Checked Then
ListBox1.Items.Add("Pickup")
Label4.Text = CStr(Val(CurrentBalance) - Val(Pickup))
Else
Label4.Text = CStr(Val(CurrentBalance) + Val(Pickup))
ListBox1.Items.Remove("Pickup")
End If
End Sub
Private Sub CheckBox13_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox13.CheckedChanged
Dim Deliver As String
Deliver = "5"
CurrentBalance = Label4.Text
If CheckBox13.Checked Then
ListBox1.Items.Add("Deliver")
Label4.Text = CStr(Val(CurrentBalance) + Val(Deliver))
Else
Label4.Text = CStr(Val(CurrentBalance) - Val(Deliver))
ListBox1.Items.Remove("Deliver")
End If
End Sub
Private Sub ChesseToastToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChesseToastToolStripMenuItem.Click
Dim CheeseToast As String
CheeseToast = "8"
CurrentBalance = Label4.Text
ListBox1.Items.Add("Cheese Toast")
Label4.Text = CStr(Val(CurrentBalance) + Val(CheeseToast))
End Sub
Private Sub GarlicToastToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GarlicToastToolStripMenuItem.Click
Dim GarlicToast As String
GarlicToast = "11"
CurrentBalance = Label4.Text
ListBox1.Items.Add("Garlic Toast")
Label4.Text = CStr(Val(CurrentBalance) + Val(GarlicToast))
End Sub
Private Sub BreadSticksToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BreadSticksToolStripMenuItem.Click
Dim Breadsticks As String
Breadsticks = "14"
CurrentBalance = Label4.Text
ListBox1.Items.Add("Bread Sticks")
Label4.Text = CStr(Val(CurrentBalance) + Val(Breadsticks))
End Sub
Private Sub CashToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CashToolStripMenuItem.Click
ListBox1.Items.Add("Paying by Cash")
End Sub
Private Sub ChequeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChequeToolStripMenuItem.Click
ListBox1.Items.Add("Paying by Cheque")
End Sub
Private Sub DebitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DebitToolStripMenuItem.Click
ListBox1.Items.Add("Paying by Debit Card")
End Sub
Private Sub CreditCardToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreditCardToolStripMenuItem.Click
ListBox1.Items.Add("Paying by Crebit Card")
End Sub
Private Sub VoucherToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VoucherToolStripMenuItem.Click
Dim Voucher As String
Voucher = "5"
CurrentBalance = Label4.Text
ListBox1.Items.Add("Voucher")
Label4.Text = CStr(Val(CurrentBalance) - Val(Voucher))
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
Private Sub MessageBox(ByVal p1 As String)
Throw New NotImplementedException
End Sub
Help would be much appreciated.