Results 1 to 5 of 5

Thread: How to use control arrays

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    5

    Unhappy How to use control arrays

    hai friends,
    Throw light on how to use control arrays. i understood that if controls performing the same task can be grouped under a array but my problem is

    + buttons has to increment by 1 for each event.
    there are 3 buttons .
    but in the case of 2 button the condition to be checked is
    the number should not exceeed 23 and in the remaining cases
    59. How to include such conditions in an array.

    Bye

  2. #2
    Hyperactive Member SoftwareMaker's Avatar
    Join Date
    Mar 2001
    Location
    Elbonia with Dilbert and Wally
    Posts
    322
    Dim objButton as CommandButton

    For each objButton in Me.Controls
    If objButton.Caption = "Do this" then
    'Do this
    Endif
    Next

    OR

    Dim objControl as Control

    For each objcontrol in Me.Controls
    If Typeof objcontrol is CommandButton then
    If objButton.Caption = "Do this" then
    'Do this
    Endif
    Endif
    Next
    William T
    Software Architect / Chief Software Developer
    Softwaremaker.Net Pte Ltd
    http://www.Softwaremaker.net

    *** Things are always the darkest before they go pitch black ***

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    SoftwareMaker, you are using control enumeration, not basic control arrays.

    sudir_ks, can you be more precise as to what you want to do ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4
    Hyperactive Member SoftwareMaker's Avatar
    Join Date
    Mar 2001
    Location
    Elbonia with Dilbert and Wally
    Posts
    322
    Ooppss..

    Sorry...Control Arrays are created by using controls on a form with the same name but with different indexes.

    so you have 5 CommandButtons on the same form with the same name such as cmdNavigate. They will all have different indices. Try creating 2 controls on a form with the same name and VBIDE will ask you if you want to have a control array. Say Yes...

    So you will have 5 command buttons with the reference
    cmdNavigate(0)
    cmdNavigate(1)
    cmdNavigate(2)
    cmdNavigate(3)

    From there, you can refer to any one of these controls by a method like this

    For i = 0 to cmdNavigate.Count

    cmdNavigate(i).Caption = "Button " & i

    Next

    Thanks plenderj for highlighting my mistake
    William T
    Software Architect / Chief Software Developer
    Softwaremaker.Net Pte Ltd
    http://www.Softwaremaker.net

    *** Things are always the darkest before they go pitch black ***

  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    I still dont know what you're trying to acheive sudir_ks.
    Take a look at the attachment. It might explain it for you ?!
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

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