Re: visual basic 6 - help looping through checkboxes

Tech-Archive recommends: Fix windows errors by optimizing your registry



<zerbie45@xxxxxxxxx> wrote in message
news:99f43a80-651e-4252-bf4f-231a59855e5c@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

If anybody could show a very simple example of how this would be coded
I would be most grateful!

There are so many ways to approach this, it's hard to say without having
more info. Are the checkboxes part of a control array? If not, this is about
as straight forward as it gets....
'==========
Private Sub Command1_Click()
If Check1.Value = vbChecked Then
'do some work
End If
If Check2.Value = vbChecked Then
'do some work
End If
End Sub
'==========

This actually "loops" thru all controls on a form, looking for checkboxes.
If found, it does work based on the checkboxes name
'==========
Private Sub Command1_Click()
Dim cb As Control
Dim sName As String

For Each cb In Controls
If TypeOf cb Is CheckBox Then
If cb.Value = vbChecked Then
sName = cb.Name
Select Case sName
Case "Check1"
'do some work
Case "Check2"
'do some work
End Select
End If
End If
Next

End Sub
'==========

This loops thru an array (Control Array) of checkboxes and, if checked, does
the work associated with that checkbox (based on its Index in the array)
'==========
Private Sub Command1_Click()
Dim cb As CheckBox
Dim sName As String

For Each cb In Check1
If cb.Value = vbChecked Then
Select Case cb.Index
Case 0
'do some work
Case 1
'do some work
End Select
End If
Next

End Sub
'==========





--
Ken Halter
Part time groupie


.



Relevant Pages

  • Re: Adding Checkboxes to a Listbox at Runtime
    ... That is certainly a valid option. ... I figured I could wrap the list control into a user control. ... defaults for style (no checkboxes) and for multiselect. ... Private Sub Command1_Click ...
    (microsoft.public.vb.general.discussion)
  • Re: Adding Checkboxes to a Listbox at Runtime
    ... doing this means the control gets the ... defaults for style (no checkboxes) and for multiselect. ... Private Sub Command1_Click ...
    (microsoft.public.vb.general.discussion)
  • Re: Loading UserForm Controls (with a twist!)
    ... Private Sub UserForm_Initialize ... I have a UserForm that contains a multipage control. ... and each Frame contains several CheckBoxes. ... the Cell A1 will contain the Value "Caption 1; ...
    (microsoft.public.excel.programming)
  • Re: Adding Checkboxes to a Listbox at Runtime
    ... doing this means the control gets the ... defaults for style (no checkboxes) and for multiselect. ... Private Sub Command1_Click ... Dim iTheOther As Integer ...
    (microsoft.public.vb.general.discussion)
  • RE: Actual Date
    ... control is populated programmatically as it is in this case. ... The only thing wrong with that is that now the calendar ... Private Sub cmdMonthDown_Click ... Select Case KeyCode ...
    (microsoft.public.access.gettingstarted)