Hi,

Easy way to create/copy from a container i.e. Tab/Frame to another.

Given a VB6 program with a form with a Tab Control. Each tab has a frame and many controls (textboxes, radio buttons, labels, combos, etc. each of which is a control array. 1 per tab/frame).

We have a need to expand from our current tab max to about 20.

We need a dynamic way of creating a entire new tab, frame and all the other controls (in the control array).

I know that you can add a tab by increasing ssTab1.tabs. And the frame via a Load.

BUT it seams that you need to do each Control array separately. Requiring a lot of coding. (Each control from an existing tab would need to looked at the based on the name to do a Load as
for each CTL in Form
Select Case Ctl.Name
case "ComboArray1"
Load Combo1
case "TextArry1"
Load TextArry1
End Select

We actually have to do this with 3 separate forms.

Is there a good way to create/copy from 1 tab to a new tab?

Please help.

Thanks

Yes it is possible to make a generic subroutine to do what you want to, to reduce your code on the instantation but either way it may increase your code on the other end.

Use a module, create a public sub with arguements that accepts the form, the frame to copy, and the destinition tab to instantiate the new controls on.

The form arguement is to enumerate through the controls that are on the form and you would test the controls container property against the passed in frame. If true then you know you need to duplicate that control. Don't forget to set the new instantiated controls container.

The specific tab is for setting the container property of the frame to the specific tab.

Good Luck

The problem when I tried it is that the Load to create a new Control Array needs the actual Control Array Name.

i.e.
Tab 0, Frame 0
ComboArray1 and ComboArra2 are control arrays with on the same frame and that there is an instance of each on each frame.
as Tab 0/Frame 0 has ComboArray1 Index 0 and ComboArray2 Index 0. On Tab 1/Frame 0 has has ComboArray1 Index 1 and ComboArray2 Index 1.

I now wish to create Tab 2, Frame 2.
ssTab1.tabs = 2
Load Frame
Above works fine.

Now I need an index 2 of Combo1 and Combo2.
I have to do a Load of ComboArray1 and CombaArray2 (using the specific names).

The Load does NOT accept Combo1. (Err 361, Can't Load or unload this Object) It seems to need specific instance of the control which is what I am trying to avoid. (too many difference control arrays).

Thanks

Yes, I know. I do not have a problem with the frames and the Frame is loading fine. It is just all the other controls in the frame.

Okay, loading a frame based upon a frame with controls placed on it will not instantiate those contols. You also have to load those controls and set their container property as I previously said/wrote/typed.

Good Luck

It seems that it can work if a variant is used
Dim V, CTL as Control
SSTab1.Tabs = SSTab1.Tabs + 1
SSTab1.Tab = SSTab1.Tabs - 1
NewTabInt = SSTab1.Tab
Load fraBase(NewTabInt)
fraBase(NewTabInt).Visible = True
Set CTL = Text1(0)
Set V = Form1.Controls.Item(CTL.Name)
Load V(2)
Set V(2).Container = fraBase(NewTabInt)
V(2).Visible = True

This article has been dead for over six months. Start a new discussion instead.