Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dynamically Add / Load Usercontrol ControlArray in Runtime.

Posted on 2011-02-21
3
Medium Priority
?
1,133 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
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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

824 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