Solved

Dynamically Add / Load Usercontrol ControlArray in Runtime.

Posted on 2011-02-21
3
1,128 Views
Last Modified: 2012-05-11
Hello Experts,

I have a VB6 project in which I have the normal application (forms etc) and 1 usercontrols which I've developed.

I have added one instance of the usercontrol on the form as a control array and dynamically load and place multiple instances of it on the Form as and when required. This is all nice and smooth.

Now I have created a second user control within the project. This user control is essentially the same as the initial usercontrol, sharing the same properties and events. The only exception is the interface. I've made this small and compact - compared to the initial one, which is quite big.

On the application, I allow the users to set their preference on which version of the user control they'd like to see - the Standard or the Compact.

Based on the user preference, I should dynamically load the controls on screen.

On code, I use a control array and have name the control as Cabin1(x), so all manipulations, property changes are for Cabin1(x).

Now what I need to do is, Whatever control the user may select (Standard / Compact), I need that control to have the name Cabin1 and it should be created as a control array, so I can load multiple instances of it in Runtime and reference it as Cabin1(x).

How do I do it?
0
Comment
Question by:shaf81
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 34942926
If there were a way to place a generic "object" (i.e. Dim MyObject as Object) and have a control array of type "objects", that could take care of allowing you to use either control as the object.  But I don't know of a way to do that.

The only thing I can think of is to create a third control that simply holds one instance of BOTH of the other controls, and a flag that indicates which is the active control.  Have the excact same set of public functions, subroutines, and properties.  But everyone of these public members would be to check the flag to see which object is the active object and call the corresponding member of the active object.  (Of course the property that sets the flag would also make the desired control visible, and hide the other).
0
 
LVL 7

Accepted Solution

by:
kemi67 earned 500 total points
ID: 34943582
i've tested this solution and it works for an option button.
I have a form with two option buttons on array: Option1 and Option2
In the Form there is the index 0 of Option1 and Option2

Dim general As Variant
dim i as integer
i=0
If strUserChoise="Type 1" then
  Set  general = Option1
else
  Set  general = Option2
End If
i=i+1
Load general(i)
general(i).Visible=true


0
 
LVL 3

Author Comment

by:shaf81
ID: 34948980

kemi67: Genius. Works like a charm. Such a simple solution, and I never thought of that! Thank you.

HooKooDooKu: Good alternative suggestion. Thanks. However, I'd have to go with kemi67's answer for its simplicity.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question