Subscribe to [FP-0] Discotinued        RSS Feed
-----

Menu Building Pt. 2 Groupbox Coding

Icon Leave Comment
Now that we have our groupbox and checkbox set up, lets put a purpose for them along with the dims

We are going to start with the sauce groupbox because the other groupboxes have some special code which I will get into later

  Private Sub CheckMustard_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckMustard.CheckedChanged
        If CheckMustard.Checked = True Then
            Sauce = Sauce + 1
            Total = Total + 1
        End If
        If CheckMustard.Checked = False Then
            Sauce = Sauce - 1
            Total = Total - 1
        End If
        If Sauce = 3 Then
            For Each CheckBox In groupSauce.Controls
                If CheckBox.checked = False Then
                    CheckBox.enabled = False
                End If
            Next
        Else
            For Each CheckBox In groupSauce.Controls
                CheckBox.Enabled = True
            Next
        End If
        If Total = 9 Then
            For Each CheckBox In groupTopping.Controls
                If CheckBox.checked = False Then
                    CheckBox.enabled = False
                End If
            Next
            For Each CheckBox In groupSauce.Controls
                If CheckBox.checked = False Then
                    CheckBox.enabled = False
                End If
            Next
            For Each CheckBox In groupMeat.Controls
                If CheckBox.checked = False Then
                    CheckBox.enabled = False
                End If
            Next
            For Each CheckBox In groupCheese.Controls
                If CheckBox.checked = False Then
                    CheckBox.enabled = False
                End If
            Next
        Else
            If Cheese < 3 Then
                For Each checkbox In groupCheese.Controls
                    checkbox.enabled = True
                Next
            End If
            If Toppings < 3 Then
                For Each checkbox In groupTopping.Controls
                    checkbox.enabled = True
                Next
            End If
            If Sauce < 3 Then
                For Each checkbox In groupSauce.Controls
                    checkbox.enabled = True
                Next
            End If
            If Meat < 3 Then
                For Each checkbox In groupMeat.Controls
                    checkbox.enabled = True
                Next
            End If
        End If
    End Sub


Explaination

First its checking to see that when you click the checkbox, Is it being checked or unchecked.

If its checked, It is adding 1 to the Dim for that group. In this case it is sauce. At the same time it is adding 1 to total.
If unchecked, It does the opposite by subtracting 1 from Suace and Total

Next, its checking to see if Sauce counter reached 3, This happens when 3 checkboxes in that group are checked.
I made it that you can choose up to 3 sauces and no more. You can change the number if you want but you would have to modify some more coding later.

If Sauce = 3 then it will disabable all checkboxes in that groupbox that are unchecked. Any that are checked, then they will be enabled and if you decide to uncheck those, all the checkboxes will be enabled. This prevents users from checking more than 3 sauces. there are simpler ways to do this but I find this more convenient for the user.

After it checks Sauce, it will check Total.
The total amount of items you can put in your meat is 9 (Can be changed)

If total = 9 or 9 checkboxes checked in total from the 4 groupboxes then all checkboxes that are not checked will be disabled ff Cheese, Meat, Topping < 3

Why < 3 ?

Well, if there is more than 3 then the checkboxes would have already been disabled in that group

Scenario/test

So if you check
2 meat items
2 cheese items
3 toppings items
Total = 7

Right now
Meat and Cheese groupbox are enabled because total is not yet 9 nor Meat and Cheese = 3
Toppings is dissabled because Topping = 3 and no other groups are disabled because again, Total does not = 9

If you uncheck any topping, then the whole group will be enabled


Copy this code to all other checkboxes in the Sauce groupbox while changing only 1 part.
 If CheckMustard.Checked = True Then
            Sauce = Sauce + 1
            Total = Total + 1
        End If
        If CheckMustard.Checked = False Then
            Sauce = Sauce - 1
            Total = Total - 1

Change CheckMustard with the name of the checkbox you copied the code on (The name of the checkbox)

Play around with checking and unchecking the checkboxes. You will only be able to disable the Sauce group because total will never = 9 but if you change 9 to 3 it will dissable all groups. If there are any problems that you encounter pleas let me know.

0 Comments On This Entry

 

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

January 2022

S M T W T F S
      1
2345678
9101112131415
161718192021 22
23242526272829
3031     

Tags

    Recent Entries

    Recent Comments

    Search My Blog

    2 user(s) viewing

    2 Guests
    0 member(s)
    0 anonymous member(s)