Creating Many Controls at Runtime in VB6

I am writing an application in VB6. As part of a form I have an indefinite number of tabs (chair1, chair2 etc) which should each present the same set of controls. Each tab (set of identical controls) will store different data.
 
I get the feeling I'm overlooking something obvious, but is there really no neat neat way or replicating all those controls (i.e. from a 'template frame' at runtime for each new tab created? (I do not want to emulate the switching of tabs by reloading each tabs different set of data into the same controls as the user switches between tabs). As far as my knowledge suggests the only way for me to do this at runtime (i.e. but not creating tons of copies of the these controls & showing/hiding them) is by creating and positioning them all *one by one* through code (using the Load statement etc). Can I not somehow replicate the picture box/frame they are all contained within! This does not seem to work but is really what I want to do!
 
Any help would be greatly appreciated, however please do not let me waste your time. Thank you.
phoenixcsAsked:
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.

PaulHewsCommented:
>Can I not somehow replicate the picture box/frame they are all contained within!

You could create a UserControl that contains the frame and component controls.  It isn't a trivial undertaking however.  The easiest way would be to wrap the control creation into a sub that you could call to create a control array of the frames.

Create a template frame with the controls you want on it.  Set the index property of the frame and every contained control to 0.  Set the template's visible = false.

Here's a simple example with a template frame with a picture box and command button:

Option Explicit

Private Sub Form_Load()
    Dim i As Integer
   
    For i = 1 To 5
        NewFrame i, 60, (i - 1) * Frame1(0).Height + 60
    Next
   
End Sub

Private Sub NewFrame(Index As Integer, x As Long, y As Long)
    'load
    Load Frame1(Index)
    Load Command1(Index)
    Load Picture1(Index)
    'Set container
   
    Set Command1(Index).Container = Frame1(Index)
    Set Picture1(Index).Container = Frame1(Index)
   
    'Position
    Command1(Index).Move Command1(0).Left, Command1(0).Top
    Picture1(Index).Move Picture1(0).Left, Picture1(0).Top
    Frame1(Index).Move x, y
   
    'Set visible
    Frame1(Index).Visible = True
    Command1(Index).Visible = True
    Picture1(Index).Visible = True
End Sub
luthvCommented:
If the control elements is the same for each tab, I would suggest using just one set of controls, and then refresh the data displayed on each tab click event.
This way you don't have to add tons of new controls at run time, which is very costly, windows resource are limited especially on older win9x system.
You can store the data on a recordset or array of user defined type.
A pseudo code for this would be:

Load your data into array/recordset
set the tab count property to match the recordcount
On tab changed event :
- Save the modified data (if any)
- refresh displayed data for the tab index requested

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
phoenixcsAuthor Commented:
PaulHews - Thank you very much for your help. What you described as your recommended solution is what I was trying to avoid, though I fully accept it is possibly the most appropriate from a range of limited solutions.
I very much like your custom control idea, I have seen this done (i.e. complete programs with each 'screen' consisting almost entirely of custom controls) but it did not occure to me that this could be a solution to my problem.

luthv - I accept your point and I was beginning to come round to this idea myself despite the fact that I stated I wanted to try and avoid this. I have been thinking about how to make the best use of resources and I suppose your suggestion is the most applicable.

I do like the custom controls idea - it seems to follow all this containment/encapsulation/'neat coding' ideas, but in this case I believe it would put more strain on the system. Instead I will use a recordset and load data into the same set of controls.

I am a little lost with awarding the points. Both of you have given me valuable advice... and though I am leaning towards luthv answer I did say in my question that 'I do not want to emulate the switching of tabs by reloading each tabs different set of data into the same controls as the user switches between tabs'. Would you both be happy if I split the points 125/125?

This is the first time I have ever got round to posting a question on EE and I am very impressed... I will be trying to earn some points (or maybe, depending on time, cheat and buy some) so I can easily gain access to more of the knowledge available here!

Lastly, I am a student (just finished A-levels) and will probably not get the time, but would you recommend I try and move over to .NET or stick with VB6 as long as I am happy? Thanks.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

luthvCommented:
I guess I miss the point in your question about not wanted to emulate switching tabs, if not, my answer would be 'Yes you have missed something obvious, since you already answered your own question' :)

As for moving .NET, it's a long debate as not everyone agreed to one point over another, for me, I use both, and from time to time the knowledge you gain in VB6 will make a great benefit in .NET and vice versa (If you've heard about VBCorlib project, that attemps to port .NET mscorlib to VB6 classes with same functionality, then you'll know what I meant).
And again you already answered your own question, as long as you're happy then that's the most important thing
PaulHewsCommented:
phoenixcs however you want to deal with the points is fine by me.  And luthv, I haven't seen your contributions on this board before this, but I sincerely hope we see more.  :)
phoenixcsAuthor Commented:
Hope your happy with the points gentlemen (if your are indeed both gentlemen...) ... I figured that was fair. Thanks a lot for the help, Regards. Tom
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.