How to get property values of classes that implement an interface in the Locals window?

前端 未结 1 1499
旧巷少年郎
旧巷少年郎 2020-12-16 12:49

This is really bothering me and hindering my development/debugging. Whenever I declare a variable type of the interface I\'m implementing, the Locals Window doesn\'t show it

相关标签:
1条回答
  • 2020-12-16 13:02

    I could be wrong, but I think this may be something to do with the way classes are instantiated in VBA.

    For example:

    Dim oClass1 as Class1
    Set oClass1 = new Class1
    

    Is different than

    Dim oClass1 as New Class1
    

    In the second case I believe the constructor doesn't get called until the property is accessed.

    If you try this, it is sees the property in the Watch window. Notice the New for the IClass - just for Demonstration - I know its not the way to do that :)

    Public Sub test1()
    
        Dim x As Class1
        Dim y As IClass
    
        Set y = New IClass
        Set x = New Class1
        Debug.Print x.Name
        Debug.Print y.Name
        Stop
    
    End Sub
    

    I suspect its something to do with that and the watch window requires this ... maybe...

    0 讨论(0)
提交回复
热议问题