Skip to content

Instantly share code, notes, and snippets.

@rikukissa
Created August 16, 2018 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rikukissa/dc9b0b598cec5132010b7dad6828bdcd to your computer and use it in GitHub Desktop.
Save rikukissa/dc9b0b598cec5132010b7dad6828bdcd to your computer and use it in GitHub Desktop.
Dictionary printer for Visual Basic
Function PrintDict(Dict as Dictionary, Optional ByVal Stack as String = "")
For Each Key In Dict.Keys()
If TypeOf Dict(Key) Is Dictionary Then
Debug.Print Stack & Key & ":"
PrintDict Dict(Key), Stack & " "
Else
Debug.Print Stack & Key & ": " & Dict(Key)
End If
Next
End Function
@quinnjin78
Copy link

Hi, is this for the standard Scripting Dictionary in Windows?
I'm using a VBA one for excel from git hub...
It's not playing nice with a for each loop
Would this function do the trick?

@rikukissa
Copy link
Author

I think it is for the standard one yes 🤔

https://excelmacromastery.com/vba-dictionary/#A_Quick_Guide_to_the_VBA_Dictionary

Have you done the first item from this list?
“Microsoft Scripting Runtime”(Add using Tools->References from the VB menu)"

@quinnjin78
Copy link

quinnjin78 commented Jun 28, 2020

I haven't yet as I want this app to function on a Mac also, so don't want to rely on the built in Scripting Dictionary....
There is another version that I may go back to....

@rikukissa
Copy link
Author

Sure 👍 you can achieve the same with any Dict type just by modifying the code a bit. The basic idea of how the inputted Dict is looped through should be the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment