Lesson VIII.           Checkbox

 

Objectives

ü       To be able to use and be familiar with the Checkbox and its properties

ü       To be familiar with the different Checkbox styles

 

 

 

 

 


CheckBoxes work just like the OptionButton, with two differences: a selected CheckBox shows the selection with a checkmark and are never mutually exclusive.  Therefore, the user can select one or more CheckBoxes even if those boxes reside in the same Frame or on the same Form.

 

Examples of Checkboxes

 
 

 

 

 


How do I know if a CheckBox has been checked?  A CheckBox has a value property that may be 0, 1, or 2.  When the value of this property is 0, the CheckBox is currently unchecked.  If the value is 1, the CheckBox is checked.  The CheckBox is disabled if this value is equal to 2.

 

CheckBoxes may also look like CommandButtons (only that a checked graphical CheckBox appears in a pressed state).  Just set the Style property to 1: Graphical (the examples above are CheckBoxes of Style set to 0: Standard, which is the default).  The following Form illustrates the various CheckBox property options available.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

 


The application below demonstrates the use of CheckBoxes.  The application counts how many items have been checked and displays the number when the user presses the “Ok” button.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Private Sub cmdOk_Click()

    Cnt = 0

    If chkMath.Value = 1 Then

        Cnt = Cnt + 1

    End If

    If chkScience.Value = 1 Then

        Cnt = Cnt + 1

    End If

    If chkLiterature.Value = 1 Then

        Cnt = Cnt + 1

    End If

    If chkHistory.Value = 1 Then

        Cnt = Cnt + 1

    End If

    lblOutput.Caption = "You have checked " & Str(Cnt) & " subject(s)."

End Sub

 

 

Save your work as Lesson8.vbp.

 

 


1.       Create a program that computes for the price of a pizza based on the following:

            Thin Crust                     P 60.00

            Thick Crust                    P 95.00

           

            Add-ons:

            Extra Cheese                 P 8.00

            Extra Ham                     P10.00

            Extra Onions                  P 5.00

 

            Dine Out                        additional P 20.00

 

The total cost should reflect in a Label.  Your application should look like the following Form:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2.   Make a program that formats the Label’s display using 3 CheckBoxes.  The CheckBoxes are: Bold, Italic, and Underlined.  If the user checks Bold, then the Label’s caption is made bold.  Refer to the Form below.

 

 


 

[ Home ]