Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 921755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:54:57+00:00 2026-05-15T18:54:57+00:00

I have created a simply Pizza program (for a summer project not education related)

  • 0

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.

  • 1 1 Answer
  • 4 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:54:58+00:00Added an answer on May 15, 2026 at 6:54 pm

    Some principals of VB.NET:

    • Always turn Option Strict on (I’ve seen horrors because of that)
    • You can directly assign values to variables like this: Dim s As String = "MyString"
    • Do yourself a favor and drop the Microsoft.VisualBasic-Namespace from your project and start using the new classes (like MessageBox instead of MsgBox).*

    To your project:
    A better way of refactoring might would be to simply stuff everything into a Dictionary(Of String, Decimal), that might work better.

    Private prices As New Dictionary(Of String, Decimal)
    Private balance As Decimal = 0D
    
    ' Add this to the constructor '
    prices.Add("Ham", 1D)
    prices.Add("Banana", 1D)
    prices.Add("Pineapple", 1D)
    ' etc. ... '
    
    For Each item As KeyValuePair(Of String, Decimal) In prices
        CheckedListBox1.Add(item.Key)
    Next
    
    ' End of Constructor '
    
    ' Don't forget to give your Controls meaningful names!
    Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e As ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
        If e.NewValue Then
            balance += prices(CheckedListBox1.Item(e.Index))
        Else
            balance -= prices(CheckedListBox1.Item(e.Index))
        End if
    
        Label4.Text = balance.ToString("C2")
    End Sub
    

    *: As Konrad Rudolph pointed out, this might be a good solution for Console-Projects, if you don’t want to include the Forms-Namespace. Though, I disagree on that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a class that is simply THIS Class UserControlBase Inherits UserControl End
I have created a java SE application that uses the mysql database using mysql
I have created a custom control that simply draws a grid of squares on
I have created a file called myblock.phtml in frontend\default\default\layout\mytemplate .It simply displays a check
I have created a c/c++ program which uses opencv library. I want to convert
I have created a setup project in VS2008. My WinForms app uses .NET 2.0,
I have created a couple of simple functions in VB.NET that simply return a
i have created a simple public ref class in the vc++ project, which is
I have created alot of stored procedures in my application that return the result
i have created a model class to connect with database with a function that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.