Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically creating a CWDataSocket object

Hi.

I would like to programmatically create an instance of the CWDataSocket in my class module. I have tried it like this:

' In the declarations section
Private WithEvents m_ds As CWDSLib.CWDataSocket

' In the Class_Initialize
Set m_ds = CreateObject("CWDSLib.CWDataSocket")

I'm trying to implement a simple wrapper class to read/write data on an OPC server via CWDataSocket. Then I have intended to create an array of these wrapper objects to connect to multiple OPC items. The line 'Set m_ds = CreateObject("CWDSLib.CWDataSocket")' in the code excerpt above causes a "Run-time error '13': Type mismatch" to occure. Is it possible at all to create CWDataSocket object on the fly instead of dragging the objects on a Form?

- Asko
0 Kudos
Message 1 of 3
(7,032 Views)
Hello

Looks like your trying to setup early binding of the control. Try this

Go to Project >> Components and remove the reference to CW Datasocket. This will remove the control from the controls toolbar. Now go to Project >> References, and add a reference to nids.dll from your system32 folder. The reason you had to remove it from the components list was because VB 6 does not let you add the same component as a reference and a component. And to use early biding, you need to add the activex control as a reference

I replaced the call to createobject with

Set m_ds = New CWDSLib.CWDataSocket

Try running the app again. It got rid of the runtime error for me

Hope this helps
Bilal Durrani
NI
Message 2 of 3
(7,027 Views)
Hello!

Yes, that was exactly what I was trying to do. Thank you.

- Asko
0 Kudos
Message 3 of 3
(7,021 Views)