VB 6 is fading far enough in the past to make it worthwhile to review the feature we're trying to duplicate. Here's what the Microsoft VB 6 documentation says about control arrays:
A control array is a group of controls that share the same name and type. They also share the same event procedures. A control array has at least one element and can grow to as many elements as your system resources and memory permit ... Elements of the same control array have their own property settings. Common uses for control arrays include menu controls and option button groupings. Visual Basic includes the ability to dynamically add unreferenced controls to the Controls collection at run time.
To illustrate how to use the Compatibility.VB6 namespace in VB.NET, let's take the suggestion of the first article and actually upgrade one. Microsoft's documentation tells you how to create a dynamic control array in VB 6:
You can add and remove controls in a control array at run time using the Load and Unload statements. However, the control to be added must be an element of an existing control array. You must have created a control at design time with the Index property set, in most cases, to 0. Then, at run time, use this syntax:
Load object(index%)
Unload object(index%)
Using Microsoft's instructions, I created this VB 6 program:
Dim ControlIndex As Integer
Private Sub Form_Load()
ControlIndex = 0
End Sub
Private Sub AddLabel_Click()
ControlIndex = ControlIndex + 1
Load LabelControlArray(ControlIndex)
LabelControlArray(ControlIndex).Visible = True
LabelControlArray(ControlIndex).Top = _
LabelControlArray(ControlIndex - 1).Top + 300
End Sub
Private Sub DelLabel_Click()
If ControlIndex > 0 Then
Unload LabelControlArray(ControlIndex)
ControlIndex = ControlIndex - 1
End If
End Sub
Opening the VB 6 project with VBE automatically calls the VBE Upgrade Wizard and the project coverts with zero errors.
The actual code for the form and the two buttons is almost unchanged in the converted project. Only the substitution of Short for Integer and the VB6.PixelsToTwipsY conversion seem to be present. The real changes show up in the normally hidden Form1.Designer.vb. (Remember that Show All Files has to be selected to see most of what we discuss from this point on.) Let's see what they are.

