Can't get ActiveX to work.

I want to communicate with a Modbus device using a third party ActiveX. I am not sure if I should use OLEContainer or add the ActiveX directly to the project. Since the ActiveX is windowless, I have been working with the latter option.

I added the ActiveX to the project pane. Two entries, Mbaxp and MBAXPLib appear in the contents pane. I then added the following code to a button Action event.

  Dim e As Integer
  Dim ConnectionStatus As Boolean
  Dim Mbaxp1 As MBAXPLib.Mbaxp
  Dim conType As MBAXPLib.enumConnection
  conType = enumConnection.TCP_IP
  Mbaxp1.Connection = conType
  Mbaxp1.IPAddr1 = 192
  Mbaxp1.IPAddr2 = 168
  Mbaxp1.IPAddr2 = 254
  Mbaxp1.IPAddr1 = 128
  Mbaxp1.TCPIPPort = 502
  Mbaxp1.Timeout = 1000
  Mbaxp1.ConnectTimeout = 2000
  ConnectionStatus = Mbaxp1.OpenConnection
  e = Mbaxp1.GetLastError
  if e = 0 Then
    MsgBox("Connection success")
  ElseIf e = 34 Then
    MsgBox("Connection timeout")
  ElseIf e <> 0 Then
    MsgBox("Connection Error")

When I run the program, there is no syntax error but when I click the button to which the code is attached, the program stops running at the point shown on the attached image. The object Mbaxp1 retruns a nil value.

Is it that I have not done the correct declarations or I am doing the wrong?

maybe you are also affected by wrong code generation?


Christian, should it be Dim Mbaxpi As New MBAXPLib.Mbaxp ??

ah, yes of course!

I might that mistake all the time still after all these years…

I used Dim Mbazp1 As New New MBAXPLib.Mbaxp and the program went past the point in my first post
However, I am having another crash which might be related to the point raised by Christian.

The parameters are NOT set in the activeX . The program stops at resultCode value = -2147418113.
I got same crash point for two different activeX

Is there any workaround for this problem or I have to surrender?

for such a code, make it a hex number, in this case 8000FFFF. Search for that. The decimal number will normally not help.
you may end up here:

and read: E_UNEXPECTED Unexpected failure

and now maybe you check parameters and documentation on what may be the reason for this.