Question

how can i instantiate an instance of an ocx at runtime in vb6 code?

new keyword doesn't seem to work...

Invalid use of New keyword

Set bob = new bobocxlib.bobcontrol
Was it helpful?

Solution

You add it to your container's Controls collection e.g. adding an intrinsic textbox control to a VB form upon load:

Private Sub Form_Load()
  Dim txt As TextBox
  Set txt = Me.Controls.Add("VB.TextBox", "MyTextBox")
  With txt
    .Move 120, 120, 2000, 285
    .Visible = True
  End With
End Sub

The control's name is the concatenation of library name as shown in the Object Browser (VB) and class name (TextBox).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top