Results 1 to 8 of 8

Thread: [RESOLVED] Select ALL objects

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    110

    Resolved [RESOLVED] Select ALL objects

    Hi

    Can anyone tell me how to change properties of ALL OBJECTS in a form during run-time in VB6?

    ObjectName.

    I just forgot how to do this. I just remember declaring a variable as OBJECT and using a LOOP.

    for e.g. can you tell me how to change the VISIBLE property of all objects during runtime.

    I know how to change it usign the object name like bellow so I'm not asking about that.
    ObjectName.Visible = True

    Looking forward to hear.

    Thanks

  2. #2
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Select ALL objects

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     Dim temp As Object
    4.  
    5.     For Each object In Me
    6.         object.Visible = False
    7.     Next object
    8.  
    9. End Sub

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Select ALL objects

    In code like that I would suggest adding On error Resume Next just in case there is a control that doesn't have a Visible property. (Is there one?)

    VB Code:
    1. Dim temp As Object
    2.  
    3.     On Error Resume Next
    4.     For Each object In Me
    5.         object.Visible = False
    6.     Next object

  4. #4
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Select ALL objects

    Hidden controls... timers, common dialogs. Things of that nature don't have visible properties. Good catch, Marty.

  5. #5
    Addicted Member
    Join Date
    Nov 2006
    Posts
    132

    Re: Select ALL objects

    Quote Originally Posted by getusama
    Hi

    Can anyone tell me how to change properties of ALL OBJECTS in a form during run-time in VB6?

    ObjectName.

    I just forgot how to do this. I just remember declaring a variable as OBJECT and using a LOOP.

    for e.g. can you tell me how to change the VISIBLE property of all objects during runtime.

    I know how to change it usign the object name like bellow so I'm not asking about that.
    ObjectName.Visible = True

    Looking forward to hear.

    Thanks
    Of course, not all objects have a visible property.
    If you mean to say all controls on a form, you can loop through them with the me.controls collection. However, you'll want some sort of logic to handle controls that do not have a visible property or that you want to keep visible.

    Here is a simplistic example:

    VB Code:
    1. Private Sub mnuHide_Click()
    2.     Dim c As Control
    3.     On Error Resume Next
    4.     For Each c In Me.Controls
    5.         If Not TypeOf c Is Menu Then
    6.             c.Visible = False
    7.         End If
    8.     Next c
    9. End Sub
    10.  
    11. Private Sub mnuMakeVisible_Click()
    12.     Dim c As Control
    13.     For Each c In Me.Controls
    14.         If Not TypeOf c Is Menu Then
    15.             c.Visible = True
    16.         End If
    17.     Next c
    18. End Sub

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    110

    Re: Select ALL objects

    thanks alot man
    this is exactly what i'm looking for.
    thanks for the help man now my years back of VB experience is restoring

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    110

    Re: Select ALL objects

    Thanks to all you fellows. By the time I replied the first post i've seen all the latter ones .... the error handling and the conrtol checking would definitely help me

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Select ALL objects

    Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer.

Posting Permissions

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



Click Here to Expand Forum to Full Width