forecast_api/VBA/JsonDebugPrint.bas
PhilRunninger 85829efd1d Clean up the VBA. This coincides with version 10.0 in Teams.
WARNING!  Do not assume the Excel file in this repo matches the VBA in
the repo. The decision was made to use Teams for managing changes to the
Excel tamplate because Git is ill-suited for binary files. The Excel
file will be updated from time to time, but only when something major
happens with the application as a whole.

1. Use the sheets' codenames to refer to them in code. This prevents
   breakage if the user changes the sheet name while working with the
   workbook.
2. Give the pivot tables proper, if not descriptive, names.
3. Simplify the code that detects a double-click in the pivot table.
4. Remove Windows_API as it was not being used.
5. Pare down TheBigOne to just the essential functions in Utils.
6. Refer to the data sources for the userforms' listboxes by using the
   worksheet.ListObjects collection.
2023-03-09 10:32:58 -05:00

44 lines
1.5 KiB
QBasic

Attribute VB_Name = "JsonDebugPrint"
Option Explicit
Public Sub TestPrintJSON()
PrintJSON ParseJson("[1,2,3]")
PrintJSON ParseJson("[{""a"":123,""b"":[56,7,78]}]")
End Sub
' This is definitely NOT a pretty printer. It was written merely as a debugging
' tool to make sense of the objects that come out of JsonConverter.ParseJSON.
' It doesn't format in the best way possible, but it does provide a semi-readable
' view of the data in the JSON object.
' Phil Runninger 3/1/2023
'
Public Sub PrintJSON(obj As Variant, Optional level As Integer = 0)
Dim itm As Variant
Dim first As Boolean
Select Case TypeName(obj)
Case "Dictionary"
Debug.Print String(level * 2, " "); "{"
first = True
For Each itm In obj
If Not first Then Debug.Print String((level + 1) * 2, " "); ","
first = False
Debug.Print String((level + 1) * 2, " "); itm; ":";
PrintJSON obj(itm), level + 1
Next
Debug.Print String(level * 2, " "); "}"
Case "Collection"
Debug.Print String(level * 2, " "); "["
first = True
For Each itm In obj
If Not first Then Debug.Print String(level * 2, " "); ","
first = False
PrintJSON itm, level + 1
Next
Debug.Print String(level * 2, " "); "]"
Case Else
Debug.Print String(level * 2, " "); obj;
End Select
End Sub