This content is not currently approved and is visible here for review only.

Library tutorials & articles

Working With Control Arrays of Checkboxes in VB6

The Code

You can now add the following code to handle the click events:

Option Explicit

Dim m_blnUserClick As Boolean

Private Sub chkAll_Click()
    m_blnUserClick = True
    Dim a As Integer
    For a = 0 To chkOptions.UBound
        chkOptions(a).Value = 0
    Next
   m_blnUserClick = False
End Sub

Private Sub chkOptions_Click(Index As Integer)
   If m_blnUserClick = False Then
      chkAll.Value = 0
      chkOptions(Index).Value = 1
   End If
End Sub

Private Sub Form_Load()
m_blnUserClick = False
End Sub
The way this works is the Boolean variable (m_blnUserClick) "Locks" the checkbox so that even though the onclick event is fired every time the value is changed, it doesn't change the value.

Now Save and Run the application, you are now able to make multiple selections but you can select all choices at once using the "All" box which will turn the other checkboxes off safely.

You must now add the code to ascertain which of the selections has been made.  This is simple enough, just add a Command Button to the form, change its Caption Property to "Submit" and give it a meaningful name, then double click on it and add code into its onclick event.  The code will look something like this:

Private Sub cmdSubmit_Click()
If chkAll.Value = 1 Then
      'All Selections have been made - Do appropriate code
Else
      'Check which selections have been made
      If chkOptions(0).Value = 1 Then
              'Option 1 has been selected - Do appropriate code
      End If
      etc.... 
End If

Comments

  1. 01 Jan 1999 at 00:00

    This thread is for discussions of Working With Control Arrays of Checkboxes in VB6.

Leave a comment

Sign in or Join us (it's free).

AddThis