none
Crash when viewing interface exposing array in watch window RRS feed

  • Question

  • Hi,

    My main problem is that when ever I have an interface that exposes an  array as a property and try to view it through the watch window it causes an unhandled exception that crashes excel. This is making it very hard to debug. 

    I'm aware interfaces aren't generally used like this but in the interest of providing an example of the problem I've reduced the problem down to it's bare essentials:

    I have a small interface called ITest which takes in a double array, returns a double array, and prints the values:

    Public Sub initialise(RHS() As Double)
        
    End Sub
    
    Public Property Get values() As Double()
    
    End Property
    
    Public Sub PrintValues()
    
    End Sub

    I have a small concrete class called test which implements Itest: 

    Implements ITest
    Private values() As Double
    
    Private Sub ITest_initialise(RHS() As Double)
        values = RHS
    End Sub
    
    Private Sub ITest_PrintValues()
        For i = LBound(values) To UBound(values)
            Debug.Print values(i)
        Next i
    End Sub
    
    Private Property Get ITest_values() As Double()
        ITest_values = values
    End Property

    Here's my module code that uses the interface and class:

    Public Sub main()
        'create an array to test the class with
            Dim arr() As Double
            ReDim arr(1 To 2)
            arr(1) = 5: arr(2) = 10
            
        'create the interface and set it as the test class
            Dim i As ITest
            Set i = New test
            i.initialise arr
        
        'check the object wrapped by the interface
        'actually contains the values passed in
            i.PrintValues
            
        'check that the array CAN be returned by the property
            Dim returnedarray() As Double
            returnedarray = i.values
            
        'viewing i in the watch window causes crash
            Stop
    End Sub

    So:

    • I can successfully print the values proving the interface and class work as they should and the test class contains the values
    • When I put a watch on returnedarray I can see the values proving that the property works as it should and the interface works fine.

    So there's my problem, when ever I expose a property as an array (of any type...integer, string etc) through an interface it works fine until I try and view it using the watch window.

    Points to note:

    • The actual code performs fine, it's viewing it in the watch window that crashes excel
    • "Watching" an concrete object that has a property that returns an array works fine
    • If i change the property to a function in the interface it works fine as the watch window no longer needs to display it
    • Interestingly I can cause the same error in a concrete class by having 1 property set a different properties' value in the Get statement - the code still runs but crashed when viewing the object variables in the watch window - might be a related issue?

    Anyway this is making me reluctant to use interfaces and polymorphism in any large project if I can't effectively see what an interface is set to and see it's properties at runtime for debug purposes. 

    Any help on resolving this issue would be greatly appreciated! 

    Any questions or if you need further details please ask! 

    Many Thanks

    Nick

    • Edited by NickBlick Sunday, May 13, 2018 3:39 PM additional information
    Sunday, May 13, 2018 3:35 PM

All replies

  • Hi Nick

    I have exactly the same problem as you in MS Excel - interfaces don't seem to be accessible from the locals or watch windows when they have array properties. I think in my application I may just resort to functions, as you mentioned, though this would mean losing the highly useful ability to view values on the fly during execution.

    If anyone has a solution to this or can verify it is a bug within excel I'd appreciate it too.

    Thanks,

    Harvey.

    Saturday, July 21, 2018 12:57 PM