Programming GUI 4

Topic Progress

This program adds a listbox to output what the user has ordered with the total

You will need:

  • 6 labels
  • 3 NumericUpDown
  • 1 Button
  • 1 ListBox

Click on the Button and paste the following code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  total = 0
        Label5.Text = 0
        ListBox1.Items.Clear()
        Dim small As Decimal
        Dim medium As Decimal
        Dim large As Decimal

        small = NumericUpDown1.Value * 2.0
        findTotal(small)
        ListBox1.Items.Add(NumericUpDown1.Value & " Small pizza")
        medium = NumericUpDown2.Value * 4.0
        findTotal(medium)
        ListBox1.Items.Add(NumericUpDown2.Value & " Medium pizza")
        large = NumericUpDown3.Value * 6.0
        findTotal(large)
        ListBox1.Items.Add(NumericUpDown3.Value & " Large pizza")
        If CheckBox1.CheckState = 1 Then
            findTotal(0.5)
            ListBox1.Items.Add("Extra cheese")
        End If
        If CheckBox2.CheckState = 1 Then
            findTotal(1.0)
            ListBox1.Items.Add("Extra pepporomni")
        End If
        If CheckBox3.CheckState = 1 Then
            findTotal(1.5)
            ListBox1.Items.Add("Extra anchovies")
        End If

At the top under the form code paste the following code

1
2
3
4
5
6
7
  ]
Dim total As Decimal = 0
    Private Function findTotal(ByVal num1 As Decimal)
        total = total + num1
        Label5.Text = total.ToString("####0.00")
        Return total
    End Function

The code should look like the image below (some code is missing)

Code Challenge

  • Add more extra toppings (tomato, onion …)
  • Label the pizza “margharita” then add another pizza E.g “Hot Mexican”