Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Iterating through Options Group (VB6)

    I have a series of option buttons in a frame. I want to iterate through each option button, test it for a value or set a value. There doesn't appear to be a controls collection associated with the frame. How is this done? For the entire form I woudl dim a control and do something like

    for each ctl in controls
    'do something
    next ctl

    How would I isolate it only to the controls in the frame?

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Iterating through Options Group (VB6)

    The Frame control does not have a Controls collection; you'd have to use the Container property of the individual controls on form. Example:

    <code>Private Sub Command1_Click()</code>
    <code> Dim ctl As Control</code>

    <code> For Each ctl In Form1.Controls</code>
    <code> If ctl.Container Is Frame1 Then</code>
    <code> Debug.Print ctl.Name</code>
    <code> End If</code>
    <code> Next ctl</code>

    <code> Set ctl = Nothing</code>

    <code>End Sub</code>

    Test results:

    <code>Option3</code>
    <code>Option2</code>
    <code>Option1</code>

    As noted in Object Browser:

    Property Container As object - Member of VB.OptionButton. Returns the container of an object.

    According to VB Help for Container property, the following controls can contain other controls:

    - Frame control
    - PictureBox control
    - SSTab control

    See the documentation for more details.

    HTH

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Iterating through Options Group (VB6)

    Mark,

    Thanks, that did help. What I'm finding is that at a certain point in the loop it raises an error that it doesn't support that property or method. When I put error handling around it and do a resume next, I find it is considering the menu items as part of the frame, which is no where near the frame and, well I didn't write this code originally, but there would be no reason to make it part of the frame.

    I can get around this because the developer at least had the good sense to prefix all the names with "opt" so I can test for that string. Just curious why it is considering the menu items as part of the frame's container collection.

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •