vb.net - VB - Running an if statement if only a certain number of checkboxes are checked? -
i creating pizza ordering system beginning vb class. able code 1 topping pizza when try , add more 1 topping item 2 toppings 2 other pizzas have single toppings. there way run if statement if number of checkboxes selected in group box?
private sub additems() 'declare topping variables dim topping1 string = "pepperoni" dim topping2 string = "bacon" dim topping3 string = "ham" 'declare size variables dim strpersonal string = "persoanl" dim strsmall string = "small" dim strmedium string = "medium" dim strlarge string = "large" dim strexlarge string = "extra large" 'personal single item if radpersonal.checked = true , chkpepperoni.checked = true checkedlistbox1.items.add(strpersonal & " " & topping1) end if if radpersonal.checked = true , chkbacon.checked = true checkedlistbox1.items.add(strpersonal & " " & topping2) end if if radpersonal.checked = true , chkham.checked = true checkedlistbox1.items.add(strpersonal & " " & topping3) end if 'personal 2 items if radpersonal.checked = true , chkpepperoni.checked = true , chkbacon.checked = true checkedlistbox1.items.add(strpersonal & " " & topping1 & " , " & topping2) end if if radpersonal.checked = true , chkbacon.checked = true , chkham.checked = true checkedlistbox1.items.add(strpersonal & " " & topping2 & " , " & topping3) end if if radpersonal.checked = true , chkham.checked = true , chkpepperoni.checked = true checkedlistbox1.items.add(strpersonal & " " & topping3 & " , " & topping1) end if end sub
firstly, should not testing radpersonal.checked
6 times. should testing once , nesting rest.
secondly, should not testing, instance, chkpepperoni.checked
alone first , testing again later in combination. if then, if checked in combination, going match both tests. should testing combination first , testing alone if combination doesn't match. here's how might inclined it:
if radpersonal.checked if chkpepperoni.checked if chkbacon.checked 'pepperoni , bacon elseif chkham.checked 'pepperoni , ham else 'pepperoni end if elseif chkbacon.checked if chkham.checked 'bacon , ham else 'bacon end if elseif chkham.checked 'ham end if end if
Comments
Post a Comment