Search code examples
vb6activexocx

How to declare OCX control in VB6 but not contained by a form


I'm trying to create a 2nd instance of an OCX control in a VB6 Active X EXE. The first instance of the OCX control is contained by and visible within a form in the ActiveX EXE. I'm trying to create the 2nd instance as a member of the ActiveX EXE class. This instance will not be contained by a form and will not be visible onscreen. I've been able to declare the instance but I can't find the proper syntax to initialize it with New operator.

Declaration inside ActiveX VB6 module

 Private m_ZoomSigPlus2 As SIGPLUSLib.sigPlus 

Initialization in ActiveX_Initialize() function

 set m_ZoomSigPlus2 = New SIGPLUSLib.sigPlus 

Compile error: Invalid use of New keyword

I've tried to look at how the instance that is part of the form is initialized but there doesn't seem to be an explicit New operation when the control is contained by a form. The declaration in the form is

   Begin SIGPLUSLib.SigPlus SigPlus1 
      Height          =   2415
      Left            =   0
      TabIndex        =   4
      Top             =   0
      Width           =   5055
   End

Solution

  • It seems the correct way to create an instance of the OCX Control not associated with a form is to use the CreateObject function.

    Private m_ZoomSigPlus2 As Object
    
    64  Set m_ZoomSigPlus2 = CreateObject("SIGPLUS.SigPlusCtrl.1")
    66  m_ZoomSigPlus2.InitSigPlus
    

    Some asked my reason for needing to do this. Well the OCX control works with some external hardware that captures incoming data. The OCX also has some processing methods for that incoming dataset. However when that processing is done it requires the incoming data collection to be turned off. By creating a 2nd instance I should be able to process the dataset during the capture of incoming data which is now required. One might argue that an alternate more cohesive design of the OCX could have removed the need for creating a 2nd instance but redesign of the OCX is not on the table at this time.