0

I'm trying to use COM object in following way:

Dim l
l = CreateObject("tst.Ax")
Dim err As Long
Dim st As ULong

Try

   l.AX_hdr(st, err)

   Catch ex As Exception
   MsgBox(ex.Message)
End Try

And I have error

TYPE_E_ELEMENTNOTFOUND

CreateObject works correctly, because this COM object executes some code during initialization (shows messagebox). Object should have method AX_hdr, but I don't have any idea why it can't find it. What else might be wrong? Is there are any method how to retrieve function list from COM object?

vico
  • 17,051
  • 45
  • 159
  • 315
  • 1
    When you use late binding then you need to have good documentation to know what methods and properties are implemented by the COM server. COM doesn't support Reflection. Contact the owner or author of the component. – Hans Passant Aug 10 '12 at 14:07

1 Answers1

2

If you add a reference to your COM component, you can instantiate the object using early binding:

Dim l as new tst.Ax

You will then have intellisense for all the method and properties of the component or you can press F2 to do a search using the Object Browser.

You can always remove the reference at a later date if you wish but early binding is usually preferable. I would only use late binding if you have a good reason to or not other option.

Community
  • 1
  • 1
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
  • I have added `tst.Ax` to references and have declared `Dim l as new tst.Ax`. But when I press dot after `l` variable I have selection from 5 methods - `Equals,GetHashCode,GetType,ReferenceEquals,ToString`. This is the same if I do declaration `Dim l as new nonExistingObject` – vico Aug 10 '12 at 15:27
  • `Dim l as new nonExistingObject` won't compile so I don't know how you can see any methods for it! So my guess is that you haven't declared your object correctly. Use the object browser and/or consult the documentation for your component. – Matt Wilko Aug 10 '12 at 15:38