By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,925 Members | 727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,925 IT Pros & Developers. It's quick & easy.

Iterating through all controls in a frame

P: n/a
Hi all, what I want to do is write a function to toggle the enabled field of
all controls within a frame, but what I can't figure out is how does one
iterate through all controls in a frame object?

For example, if I wanted to iterate through all controls in a form, I'd
write something like:

Dim x
For Each x In frmMyForm.Controls
x.Enabled = Not x.Enabled
Next x

But of course this will toggle the enabled field of all controls on the
entire form. Since a frame doesn't have a "controls" collection, how can I
iterate through only the controls contained in a frame? Using the above
loop I tried putting in a comparison like:

If x.Container = fraMyFrame Then
x.Enabled = Not x.Enabled
End If

But if an object is on the form, the call to .Container causes a runtime
error (same thing with .Parent). And it seems inefficient, since I'm
looping through all controls on the form, when I really only want to touch
those controls contained in the frame. If it matters, I'm using VB6.

Thanks,

Adam
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
> Hi all, what I want to do is write a function to toggle the enabled
field of
all controls within a frame, but what I can't figure out is how does one iterate through all controls in a frame object?

For example, if I wanted to iterate through all controls in a form, I'd write something like:

Dim x
For Each x In frmMyForm.Controls
x.Enabled = Not x.Enabled
Next x

But of course this will toggle the enabled field of all controls on the entire form. Since a frame doesn't have a "controls" collection, how can I iterate through only the controls contained in a frame? Using the above loop I tried putting in a comparison like:

If x.Container = fraMyFrame Then
x.Enabled = Not x.Enabled
End If

But if an object is on the form, the call to .Container causes a runtime error (same thing with .Parent). And it seems inefficient, since I'm
looping through all controls on the form, when I really only want to touch those controls contained in the frame. If it matters, I'm using VB6.


This is not as inefficient as you are thinking it is...

Dim cntrl As Control
For Each cntrl In Me.Controls
If cntrl.Container Is Frame1 Then
cntrl.Enabled = Not cntrl.Enabled
End If
Next

Rick - MVP

Jul 17 '05 #2

P: n/a
.... or

If typeof(ctl.container) is Frame then
...

If there are more than 1 frame of interest.

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:IP********************@comcast.com...
: > Hi all, what I want to do is write a function to toggle the enabled
: field of
: > all controls within a frame, but what I can't figure out is how does
: one
: > iterate through all controls in a frame object?
: >
: > For example, if I wanted to iterate through all controls in a form,
: I'd
: > write something like:
: >
: > Dim x
: > For Each x In frmMyForm.Controls
: > x.Enabled = Not x.Enabled
: > Next x
: >
: > But of course this will toggle the enabled field of all controls on
: the
: > entire form. Since a frame doesn't have a "controls" collection, how
: can I
: > iterate through only the controls contained in a frame? Using the
: above
: > loop I tried putting in a comparison like:
: >
: > If x.Container = fraMyFrame Then
: > x.Enabled = Not x.Enabled
: > End If
: >
: > But if an object is on the form, the call to .Container causes a
: runtime
: > error (same thing with .Parent). And it seems inefficient, since I'm
: > looping through all controls on the form, when I really only want to
: touch
: > those controls contained in the frame. If it matters, I'm using VB6.
:
: This is not as inefficient as you are thinking it is...
:
: Dim cntrl As Control
: For Each cntrl In Me.Controls
: If cntrl.Container Is Frame1 Then
: cntrl.Enabled = Not cntrl.Enabled
: End If
: Next
:
: Rick - MVP
:

Jul 17 '05 #3

P: n/a
I figured he wanted the specific case because his Subject said "...all
controls in a frame" (emphasis on the "a").

Rick
"Randy Birch" <rg************@mvps.org> wrote in message
news:CT********************@news01.bloor.is.net.ca ble.rogers.com...
... or

If typeof(ctl.container) is Frame then
...

If there are more than 1 frame of interest.

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:IP********************@comcast.com...
: > Hi all, what I want to do is write a function to toggle the enabled : field of
: > all controls within a frame, but what I can't figure out is how does : one
: > iterate through all controls in a frame object?
: >
: > For example, if I wanted to iterate through all controls in a form, : I'd
: > write something like:
: >
: > Dim x
: > For Each x In frmMyForm.Controls
: > x.Enabled = Not x.Enabled
: > Next x
: >
: > But of course this will toggle the enabled field of all controls on : the
: > entire form. Since a frame doesn't have a "controls" collection, how : can I
: > iterate through only the controls contained in a frame? Using the
: above
: > loop I tried putting in a comparison like:
: >
: > If x.Container = fraMyFrame Then
: > x.Enabled = Not x.Enabled
: > End If
: >
: > But if an object is on the form, the call to .Container causes a
: runtime
: > error (same thing with .Parent). And it seems inefficient, since I'm : > looping through all controls on the form, when I really only want to : touch
: > those controls contained in the frame. If it matters, I'm using VB6. :
: This is not as inefficient as you are thinking it is...
:
: Dim cntrl As Control
: For Each cntrl In Me.Controls
: If cntrl.Container Is Frame1 Then
: cntrl.Enabled = Not cntrl.Enabled
: End If
: Next
:
: Rick - MVP
:


Jul 17 '05 #4

P: n/a
Yes, I was actually thinking one individual frame, but that's a neat trick
doing all frames on a form. So thanks to both. :)

Adam

"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:Z8********************@comcast.com...
I figured he wanted the specific case because his Subject said "...all
controls in a frame" (emphasis on the "a").

Rick
"Randy Birch" <rg************@mvps.org> wrote in message
news:CT********************@news01.bloor.is.net.ca ble.rogers.com...
... or

If typeof(ctl.container) is Frame then
...

If there are more than 1 frame of interest.

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:IP********************@comcast.com...
: > Hi all, what I want to do is write a function to toggle the

enabled
: field of
: > all controls within a frame, but what I can't figure out is how

does
: one
: > iterate through all controls in a frame object?
: >
: > For example, if I wanted to iterate through all controls in a

form,
: I'd
: > write something like:
: >
: > Dim x
: > For Each x In frmMyForm.Controls
: > x.Enabled = Not x.Enabled
: > Next x
: >
: > But of course this will toggle the enabled field of all controls

on
: the
: > entire form. Since a frame doesn't have a "controls" collection,

how
: can I
: > iterate through only the controls contained in a frame? Using the
: above
: > loop I tried putting in a comparison like:
: >
: > If x.Container = fraMyFrame Then
: > x.Enabled = Not x.Enabled
: > End If
: >
: > But if an object is on the form, the call to .Container causes a
: runtime
: > error (same thing with .Parent). And it seems inefficient, since

I'm
: > looping through all controls on the form, when I really only want

to
: touch
: > those controls contained in the frame. If it matters, I'm using

VB6.
:
: This is not as inefficient as you are thinking it is...
:
: Dim cntrl As Control
: For Each cntrl In Me.Controls
: If cntrl.Container Is Frame1 Then
: cntrl.Enabled = Not cntrl.Enabled
: End If
: Next
:
: Rick - MVP
:

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.