hello guys,

I need some help: I'm writing a very simple application with visual
basic 6.
In a form I have a couple of checkboxes, where the user can check any
of them.

I need to build a procedure that loops through all these checkboxes
and start another procedure for each checkbox that is checked. I'm
sure this is quiete a simple task to accomplish but I'm not that good
with VB.

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

thanks in advance,
zz

Re: visual basic 6 - help looping through checkboxes by Ken

Ken
Wed Oct 15 14:25:30 CDT 2008

<zerbie45@gmail.com> wrote in message
news:99f43a80-651e-4252-bf4f-231a59855e5c@t41g2000hsc.googlegroups.com...
>
> 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