VB6 Tutorial 23: The CheckBox Control

Posted On 2018-04-07 by VB6Boy
Keywords:
Tags: VB6 Tutorials Windows
Views: 32

Title Uploaded Size
The_Checkbox_Control.zip 4/7/2018 6:06:10 AM 0


Looking for the more of the VB6 Tutorial? Here is the tutorial index.

In this lesson, I'll give you an overview of the CheckBox control in VB6. This is a powerful tool in the Visual Basic 6 IDE.

Unlike the OptionButton control, the CheckBox control lets you perform multiple selections, meaning that the end user of your finished software product will be able to have multiple choices from a list of items.

This control has three states : checked, unchecked and grayed. The value property determines the checkbox state.

Example

Private Sub cmdShow_Click()
    If Check1.Value = 1 Then
        Print "Checked !"
    ElseIf Check1.Value = 0 Then
        Print "Unchecked !"
    End If
End Sub

If you assign Check1.Value = 1 then the CheckBox is checked and if Check1.Value = 0 then it is unchecked. If Check1.Value = 2 then the checkbox is grayed.

Example

The previous program can also be written in the following way.

Private Sub cmdShow_Click()
    If Check1.Value = VBChecked Then
        Print "Checked !"
    ElseIf Check1.Value = VBUnchecked Then
        Print "Unchecked !"
    End If
End Sub

vbChecked and vbUnchecked are VB constants whose values are 1 and 0 respectively.

The grayed state can be set using the 'vbGrayed' VB constant whose value is 2.

Example

Program to make multiple choices.

Private Sub cmdShow_Click()
     If chkTea.Value = 1 Then
         Print "Tea"
     End If

     If chkCoffee.Value = 1 Then
         Print "Coffee"
     End If

     If chkPizza.Value = 1 Then
         Print "Pizza"
     End If

     If chkChocolate.Value = 1 Then
         Print "Chocolate"
     End If
End Sub

Apart from checked and unchecked states, there is another state called grayed state. The grayed state is used to indicate that the checkbox is unavailable.

The grayed state can be set using the value property from the Properties Window or you may want to set this property in run-time.

Example

Check1.Value = VBGrayed

Or,

Check1.Value = 2

The attached project, The_Checkbox_Control, gives you a good idea of using the checkbox control.

Looking for the more of the VB6 Tutorial? Here is the tutorial index.


About the Author

VB6Boy has posted a total of 71 articles.


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:23.20.165.182

Before you can post, you need to prove you are human. If you log in, this test goes away.




Code Links