3

I'm working on an Excel macro. Is there an option that the debugger shows all elements like it does with an array?

If not, is the only workaround the storage of my classobjects in an array after inflating the collection?

Community
  • 1
  • 1
Maik3141
  • 33
  • 1
  • 6

3 Answers3

4

You could use debug.print and write the output into the immediate window and bypass the limit that way.

I am almost certain that there is no way to increase that limit, but maybe someone else can give a def. answer on that.

rohrl77
  • 3,277
  • 11
  • 47
  • 73
  • 2
    I don't think that it is possible to change that limit. A search of the VBE object model didn't show any methods to control the debugger (though I might have missed something). Dictionaries seem to have the same limit. – John Coleman Jun 16 '15 at 13:33
  • Your example is exactly what I meant. Use a loop or for next statement to write into the immediate window. Plus one for that. – rohrl77 Jun 16 '15 at 14:07
  • you gave me the idea -- but I thought that making the output seem as similar as possible to what you see in the locals window would be a good tweak – John Coleman Jun 16 '15 at 14:14
  • 3
    Note that the immediate window into which `debug.print` prints also has a limit for the number of lines, namely 200. It would recycle the lines beyond that (push them out). So it's even worse than the 256. – GSerg Nov 21 '19 at 10:37
  • 1
    you could wrap the lines to have more than one item per line and thus increase the limit. but in principle you are right! good for pointing it out – rohrl77 Nov 21 '19 at 11:35
3

The answer seems to be no -- but the following sub might help. A simple experiment shows that it can be used in the immediate window while in debug mode:

Sub display(col As Collection)
    Dim i As Long
    Dim it As Variant
    Dim itType As String
    For i = 1 To col.Count
        it = col.Item(i)
        itType = TypeName(it)
        Debug.Print "Item " & i & " -- Value: " & it & " -- Type: " & itType
    Next i
End Sub
John Coleman
  • 51,337
  • 7
  • 54
  • 119
  • Added an updated sub to cover arrays `Debug.Print "Item " & i & " -- Values: [" & Join(it, ", ") & "] -- Type: " & itType` @JohnColeman not intended to steal any votes, if you wish to improve your answer to include my suggestion, feel free to do so and I will delete my reply – nkatsar Jun 18 '17 at 22:33
  • 1
    Note that the immediate window into which `debug.print` prints also has a limit for the number of lines, namely 200. It would recycle the lines beyond that (push them out). So it's even worse than the 256. – GSerg Nov 21 '19 at 10:38
0

In my case the elements of the collection could be arrays.

John Coleman's sub could be improved to cover (at least one-dimensional) arrays as:

Sub display(col As Collection)
    Dim i As Long
    Dim it As Variant
    Dim itType As String
    For i = 1 To col.Count
        it = col.item(i)
        itType = TypeName(it)
        If Not IsArray(it) Then
            Debug.Print "Item " & i & " -- Value: " & it & " -- Type: " & itType
        Else
            Debug.Print "Item " & i & " -- Values: [" & Join(it, ", ") & "] -- Type: " & itType
        End If
    Next i
End Sub
nkatsar
  • 1,580
  • 17
  • 15
  • 2
    Note that the immediate window into which `debug.print` prints also has a limit for the number of lines, namely 200. It would recycle the lines beyond that (push them out). So it's even worse than the 256. – GSerg Nov 21 '19 at 10:38