My Code seems to have a little bit of problem it does calculate and add all value together but it display’s on the side of the label.
I tried some other code tips by other people but it’s not working. The Problem is I don’t know how to add all of this value together. if I choose a Quantity from combo box from 1 to 10, it does not adding all value together. for example: I choose 1 pizza the price is 200 and I choose one more pizza the price is 100, then display it on the label which is 300 then if I choose 1 to 10 Quantity or Item from Combo box. for example: I choose 2 item from combo box 1 which is connected into the First pizza that cost 200 then it should display 500 Why? because its 200 * 2 = 400 then 400 + 100 = 500. (200 * 2) is the 200 is the First Pizza and the * 2 is the Quantity or Item that I choose on the Combo box. I Hope someone can help me. Here’s my Code:
Public Class Form1
Dim price As Integer = 0
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged, CheckBox3.CheckedChanged, CheckBox4.CheckedChanged, CheckBox5.CheckedChanged, CheckBox6.CheckedChanged
Dim pizza As Integer = 0
Dim multiply As Integer
If CheckBox1.Checked Then
price += 200
ComboBox1.Text = 1
Else ComboBox1.Text = 0
End If
If CheckBox2.Checked Then
price += 100
ComboBox2.Text = 1
Else ComboBox2.Text = 0
End If
If CheckBox3.Checked Then
price += 100
ComboBox3.Text = 1
Else ComboBox3.Text = 0
End If
If CheckBox4.Checked Then
price += 15
ComboBox5.Text = 1
Else ComboBox5.Text = 0
End If
If CheckBox5.Checked Then
price += 5
ComboBox6.Text = 1
Else ComboBox6.Text = 0
End If
If CheckBox6.Checked Then
price += 25
ComboBox7.Text = 1
Else ComboBox7.Text = 0
End If
Label4.Text = price.ToString("c")
price = 0
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged, ComboBox2.SelectedIndexChanged, ComboBox3.SelectedIndexChanged
Dim pizza As Integer = 0
Dim multiply As Integer
If CheckBox1.Checked Then
pizza = 200
multiply = Integer.Parse(ComboBox1.Text)
pizza = pizza * multiply
End If
If CheckBox2.Checked Then
pizza = 100
multiply = Integer.Parse(ComboBox2.Text)
pizza = pizza * multiply
End If
If CheckBox3.Checked Then
pizza = 100
multiply = Integer.Parse(ComboBox3.Text)
pizza = pizza * multiply
End If
Label4.Text = pizza
pizza = 0
End Sub
End Class
John is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.