debug Syntax for dictionaries

Certified

Board Regular
Joined
Jan 24, 2012
Messages
189
Here is a snippet of my code:
Code:
Set Results = New Dictionary

For i = 2 To UBound(Mainarray)

TheDate = Mainarray(i, 1)


' If team one is not already in dictionary then add
Results.CompareMode = TextCompare

If Results.Exists(TheDate) Then

'Results(TheDate) = Mainarray(Ecount, 1)
Tran.Update_Amount = Mainarray(i, 8) + Tran.Update_Amount

Else
Tran.Update_Amount = Mainarray(i, 8)
Results.Add Key:=Mainarray(i, 1), Item:=Tran.Update_Amount

End If

Next i

What is the syntax to debug.print this code?

Note: The item is a part of a class.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
What exactly are you trying to debug/check?

Instead of Debug.Print have you considered using the Local/Watch windows?
 
Upvote 0
To simply printing the contents of a dictionary to the Immediate window you can use this subroutine:

Code:
Sub DebugDictionary(Dictionary As Object)

Dim Key As Variant
  
  For Each Key In Dictionary.keys
    Debug.Print "Key: " & Key & "; Item: " & Dictionary(Key)
  Next Key
  
End Sub

If you want to read the contents form the watch window you would be best served having the following function in your code and putting "WatchDictionary(Results)" in the watch window in the context of your method.

Code:
Function WatchDictionary(Dictionary As Object) As Variant

Dim Arr As Variant

Dim Key As Variant
Dim x As Long

  ReDim Arr(0 To Dictionary.Count - 1)
  
  For Each Key In Dictionary.keys
    Arr(x) = "Key: " & Key & "; Item: " & Dictionary(Key)
    x = x + 1
  Next Key
  
  WatchDictionary = Arr
  
End Function
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,614
Members
452,661
Latest member
Nonhle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top