Handling events from a control array in VB6

Hi.  I'm using VB6.  On my main form there is a control array of TextBox's.

I have a class with which I would like to handle the events for this control array.  I'm setting up the association in this manner.

---- MyClass Start ----

Private m_editTextArray As Object

Private Sub Class_Initialize()
   Set m_editTextArray = fMainForm.editTextArray
End Sub

---- MyClass End ----

As you can see, I'm assigning the control array object to a member of my class.  I cannot handle events on the control array within my class..

Ideally, I'd like to be able to declare my text array, in the class, as:
Private WithEvents m_editTextArray As Object

I could then handle any events through m_editTextArray.
However, the compiler disallows this.  I've tried some variations using "As TextBox" (and WithEvents), but am having no luck.  I know that I could just declare one TextBox control per index (within my class) from the main form's control array, but that kind of defeats the purpose!

Anyone have an idea on how I can get the events to be fired and handled by my class?  Thanks.
jeffb022197Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
According to the help file for WithEvents: "You can declare as many individual variables as you like using WithEvents, but you can't createarrays with WithEvents."

So, unfortunately, I don't think it can be done in this manner.
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
What functionality were you trying to achieve with the class?  Perhaps we could help you come up with a different solution.

Idle_Mind
0
InTheWindCommented:
I'm sorry, but I just don't see the advantage to doing the event handling this way... too complicated perhaps?

What I have done in the past is assigned functions to each event. Since the arrays events all fire concurrently, it's easy to handle them all at once.

For example, if you change the text in one text control the event that fires is ..._change(index as integer)...

So, you can handle the events by determining which text box had the change event through interogating the index. If the index is zero, then you know it's the text box with the index of zero... and you deal with it accordingly.

Please clarify you needs so that we may better understand and possibly assist.

Cheers!
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

jeffb022197Author Commented:
Thanks for your comments.  I'm, admittedly, not much of a VB guru.  Here's what I'm trying to accomplish:

I have an "explorer style" user interface with a tree control on the left.  When the user selects an item from the tree, the remaining client area of the UI will display a set of controls related to the selection.  I have about 16 different tree items (and hence 16 different sets of controls).

I was "grouping" controls within a picture box (up to 64 controls sometimes), and then simply hiding all the other picture boxes and displaying the one related to the tree selection.

This solution worked great except that my main form has *so* much code within it that it was becoming unmanageable.  I was hoping to refactor some things out and move them to separate modules or classes in attempt to clean up the code and make it readable and maintainable.

My goal here is to handle events related to each set of controls within its own module.  That will keep unrelated code separate, and a lot more manageable.

Any tips?  I realize this is a broad request, but you asked  :-)
Cheers.

     -jb
0
InTheWindCommented:
jb, I have done this kind of thing in the past, as a commercial application. What I did was use a tab control and had several arrays of text boxes/labels with their own functions/factors/conditions all logic was discriminated by the index of the control array.

To make it manageable, for you the programmer, you only really need to leave yourself notes within the code to determine the function of the item you're looking at. I had about 400 objects that were running through the same module to look for their own action, triggered by an 'on click' event. When that event was fired, it looked for the control through the index and then ran that items function, which was in a separate module.

Having some of the events using the same code, with different data provided by the original 'on click', can further streamline your code, and making as much of it reusable as possible will help a great deal in simplifying the job as well.

Moving it into separate classes will actually (initially) make the program more complicated, because you are moving things out of the event. But, OOP modularization is the best way to handle multiple decision trees in the long run.

Also, if you have data you are loading to respond to each event you can speed things up by loading it into a memory array, of a structure, at start up. It takes a little longer to load up, not that much really, but increases the speed of operation by several orders as you aren't doing disk read/writes. I did this by loading my entire database into memory, granted this was just a bunch of 0's and 1's in my case though.

I can't stress enough that you will need to make lots of comments...but, you've already figured that out I'm sure. :-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jeffb022197Author Commented:
Thanks for the tips and info guys.  I split the points 50/50.

    -jb
0
InTheWindCommented:
Thanks, didn't really do it for the points :)

Just liked the question and have had some similar experience.

Good luck.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.