1

I have a ComClass which fires an event to get prices from an API. prices = priceAPI.getPrices returns a price object with several properties such as currentPrice, prevPrice etc

An example of the code to run this is below

Dim WithEvents priceAPI As newToolforUsers.ComClass

' this event is fired on update
Private Sub priceAPI_pricesUpdated()
    prices = priceAPI.getPrices
    For Each iprice In prices
        Debug.Print iprice.currentPrice
        Debug.Print iprice.prevPrice
        Debug.Print iprice.dailyHigh
        Debug.Print iprice.dailyLow
        Debug.Print iprice.dailyAvg
    Next
End Sub

The API gets updated occassionally but the manual update is often months behind so I know the price object has many more new properties.

Using the debugger the price object displays <No Variables> athough it has returned the object correctly and all of the properties are avaiable.

enter image description here

The object explorer also does not seem to reveal the properties of the price object enter image description here

Is there a way to find out in VBA all of the properties of a COM object?

2 Answers2

4

Given the COM object, there is no guarantee that its properties can be enumerated. You can still try enumerating the properties access type information, see details in this question: How does Visual Studio's debugger/interactive window dump the properties of COM Objects in .NET?

Community
  • 1
  • 1
Roman R.
  • 68,205
  • 6
  • 94
  • 158
4

What the debugger is telling you is that Price is a late-bound IDispatch interface. Pretty common, especially for event interfaces. Such an interface doesn't tell you what properties and methods are supported, you need to know the name up front. Then IDispatch::GetIDsOfNames() will map the name to a number, the DispId of the property or method. Which is then used in IDispatch::Invoke() to invoke the method or property getter/setter.

This mapping goes one way, from name to number. There is no support for going the other way. You are supposed to know the name up front, from documentation provided by the vendor or author of the component.

You could use the OleView.exe utility, File + View Typelib command to take a look at the type library embedded in the executable. You may find a better declaration for Price in there. That however isn't very likely.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536