2
votes

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
1
I suspect you have an XY problem, where you've broken your problem down to the easy portion and the impossible portion, and are asking for help with the impossible portion. OCX controls go on a form, that's what they do and their purpose for existence. The way to create one is to put it on a form. What are you actually trying to accomplish?user65839
Can you just add a second control on the form instead of trying to instantiate one in code? What is the reason to do it the way you are attempting? ThanksStayOnTarget
And when adding a second control to the form, just set the visible property to False, then the users won't see it. If you need to be dynamically adding multiple instances of this control, then make it a control array and you can add additional array element instances on the fly.MarkL
@MarkL Yes I thought of this solution and it was my next option if I couldn't figure out how to create it outside the form. However I did find how to create outside form. See my posted answerJonN

1 Answers

1
votes

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.