Results 1 to 6 of 6

Thread: Control Array in VBA

  1. #1

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Control Array in VBA

    I may be missing something very obvious here, and I have been away from programming for a couple of years, but I can't seem to create a control array, either textboxes or labels etc.
    When I copy and paste they come out as TextBox2 TextBox3 etc

    Is there an obvious answer here?

    (I expect so, but I can't find it )
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Control Array in VBA

    VBA question moved to Office Development

    Are you using Excel? Word? Access? Which VBA platform are you developing with?

  3. #3

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Control Array in VBA

    I am using Excel, sorry about that. :-)
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  4. #4
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Control Array in VBA

    Is there an obvious answer here?
    Sure: You can't.

    You could get close to a control array but it would require a lot of repetitive code to do so.
    VB Code:
    1. Private Text(2) As TextBox 'an array so we can address the controls by index
    2.  
    3. Private Sub Init 'run this at the start of the program to fill the array
    4.     Set Text(1) = Text1
    5.     Set Text(2) = Text2
    6. End Sub
    7.  
    8. Private Sub TextChange(Index As Long) 'the master change sub for a textbox, it is told the index of the textbox
    9.     MsgBox Text(Index).Text
    10. End Sub
    11.  
    12. Private Sub Text1_Change() 'catch the change event of a control
    13.     TxtChange 1 'and send it to the master change sub, along with the controls index
    14. End Sub
    15. Private Sub Text2_Change()
    16.     TxtChange 2
    17. End Sub

  5. #5

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Control Array in VBA

    Thanks - seems a bit stupit that VBA doesn't allow arrays though.

    Ah well, not that much of a problem.
    Thanks for the option you suggested.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  6. #6
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Control Array in VBA

    Have a look at my post here on creating an event handler in VBA. It will give you a good approxamation of a control array.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

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