2

Is it possible to view the members/properties of a Class within the Locals window?

When I try to view the values, the Locals window simply states "Object doesn't support this property or method."

Is there some adjustment I need to make to my Classes in order for the members/properties to be visible in the Locals window?

Here is a basic example of how I am creating a class (using a Class, an Interface and a Factory):

My Class called: "clsMyClass"

Option Explicit

Implements IMyClass

Private Type TMyClass
    MyID As Long
    MyName As String
End Type

Private This As TMyClass

Private Property Get IMyClass_MyID() As Long
    IMyClass_MyID = This.MyID
End Property

Private Property Get IMyClass_MyName() As String
    IMyClass_MyName = This.MyName
End Property

Private Function IMyClass_ChangeMyID(NewID As Long) As Long
    IMyClass_ChangeMyID = This.MyID
    This.MyID = NewID
End Function

Private Function IMyClass_ChangeMyName(NewMyName As String) As String
    IMyClass_ChangeMyName = This.MyName
    This.MyName = NewMyName
End Function

Public Sub FillData( _
    MyID As Long, _
    MyName As String _
)
    This.MyID = MyID
    This.MyName = MyName

End Sub

My Interface: IMyClass

Public Property Get MyID() As Long
End Property

Public Property Get MyName() As String
End Property

Public Function ChangeMyID(NewID As Long) As Long
End Function

Public Function ChangeMyName(NewMyName As String) As String
End Function

My Class Factory: "MyClassFactory"

Option Explicit

Public Function Create( _
    MyID As Long, _
    MyName As String _
) As IMyClass

    Dim newMyClass As clsMyClass
    Set newMyClass = New clsMyClass
    
    newMyClass.FillData MyID, MyName
    
    Set Create = newMyClass
End Function

My Test sub:

Public Sub test()
    Dim myTestClass As IMyClass
    Set myTestClass = MyClassFactory.Create(1, "Some Name")
    
End Sub

If I put a break point after myTestClass is created, this is what my Locals window displays:

enter image description here

If I Debug.Print myTestClass.MyID it prints the correct value in the Immediate window. But it would be nice to be able to explore my entire Class at a break point without having to manually print all of the values. Is this possible with VBA? If so, what do I need to change?

Blau
  • 331
  • 3
  • 12
  • 1
    For debugging purposes you can cast your IMyClass variable to a temporary variable declared as as a clsMyClass object. – freeflow Nov 14 '21 at 12:42
  • https://stackoverflow.com/questions/29146243/how-to-get-property-values-of-classes-that-implement-an-interface-in-the-locals – braX Nov 15 '21 at 07:11
  • @braX Thanks for the link; I did see this article, and the comments suggest that the only way to do this is to either not use Interfaces or write a custom .dll. I suppose I was hoping that someone knew of a better solution than that. Other comments have suggested that this is a VBA bug, but I don't know enough about it to know whether or not it is true. – Blau Nov 16 '21 at 00:40
  • I'm afraid that is probably all the information you are going to get about this. It looks like a bug to me, based on that link. – braX Nov 16 '21 at 00:44

0 Answers0