Click to See Complete Forum and Search --> : For each Ctl in xxxx, why doesn't this wok


cgchris99
October 16th, 2002, 08:03 AM
I am trying to loop thru all the controls that are in a groupbox. Here is what I am trying. This is my test code for debuggin.

Dim ctl as Control
Dim x as integer

x=form1.instance.GroupBox2.Controls.Count()

For Each ctl in Form1.instance.GroupBox2.Controls
myname=ctl.name
next

x reports back 76
So I would expect the for loop to loop 76 times. It only loops once.

Why is this? I don't know if this helps. But the GroupBox2 is actually on a TabPage also.

Thanks

Athley
October 18th, 2002, 11:34 AM
I just can't seem to replicate your problem,

Dim con As Control
Dim a As Integer
For Each con In Me.GroupBox2.Controls
a += 1
Next
MsgBox(a)

I have a groupbox2 on a tabpage with one checkbox, one radiobutton and one button, the MsgBox reports back 3.

Have I got something wrong (am I missing something with the instance thing, why do you need that?)

/Leyan