Is it possible to dynamically access/edit a nested dictionary with a "path" to that dictionary's parents?
So I am creating a dictionary of assemblies and parts, the assemblies have 'children' assemblies and parts and those assemblies have 'children' assemblies and parts...
I have a sub that generates the dictionary of children and produces childrenDocsDict
I have the dictionary that will contain all the parts nested in their assemblies allDocsDict
I have a collection that contains the path to get to the nested dictionary pathCol
Private Sub addToDictViaPath(childrenDocsDict As Dictionary, ByRef allDocsDict As Dictionary, pathCol As Collection)
Select Case pathCol.Count
Case Is = 1
Set allDocsDict(pathCol(1))("children") = childrenDocsDict
Case Is = 2
Set allDocsDict(pathCol(1))("children")(pathCol(2))("children") = childrenDocsDict
Case Is = 3
Set allDocsDict(pathCol(1))("children")(pathCol(2))("children")(pathCol(3))("children") = childrenDocsDict
Case Is = 4
Set allDocsDict(pathCol(1))("children")(pathCol(2))("children")(pathCol(3))("children")(pathCol(4))("children") = childrenDocsDict
Case Is = 5
Set allDocsDict(pathCol(1))("children")(pathCol(2))("children")(pathCol(3))("children")(pathCol(4))("children")(pathCol(5))("children") = childrenDocsDict
Case Is = 6
Set allDocsDict(pathCol(1))("children")(pathCol(2))("children")(pathCol(3))("children")(pathCol(4))("children")(pathCol(5))("children")(pathCol(6))("children") = childrenDocsDict
Case Is = 7
Set allDocsDict(pathCol(1))("children")(pathCol(2))("children")(pathCol(3))("children")(pathCol(4))("children")(pathCol(5))("children")(pathCol(6))("children")(pathCol(7))("children") = childrenDocsDict
Case Is = 8
Set allDocsDict(pathCol(1))("children")(pathCol(2))("children")(pathCol(3))("children")(pathCol(4))("children")(pathCol(5))("children")(pathCol(6))("children")(pathCol(7))("children")(pathCol(8))("children") = childrenDocsDict
Case Is = 9
Set allDocsDict(pathCol(1))("children")(pathCol(2))("children")(pathCol(3))("children")(pathCol(4))("children")(pathCol(5))("children")(pathCol(6))("children")(pathCol(7))("children")(pathCol(8))("children")(pathCol(9))("children") = childrenDocsDict
Case Is = 10
Set allDocsDict(pathCol(1))("children")(pathCol(2))("children")(pathCol(3))("children")(pathCol(4))("children")(pathCol(5))("children")(pathCol(6))("children")(pathCol(7))("children")(pathCol(8))("children")(pathCol(9))("children")(pathCol(9))("children") = childrenDocsDict
End Select
End Sub
This works but as you can see it's not exactly ideal. Is there a way to do this using some sort of recursive function?
(I'm fairly new to programming and self taught from reading documentation and there could be a huge blind spot in my knowledge, so please enlighten me!)
Can't quite figure out your dictionary structure, but I think it's easier to use a function to access your nested sub-item, and then do whatever you need with it.