Nested Dictionaries of different types

Hello everyone.

I am trying to turn an excel file containing multiple sheets into a dictionary of the following format

Sheets(“SheetName”) => Key(“KeyName”), Value or Key(“SectionName”), Value(“KeyName”)(range to another Key, Value table)

example one => MasterDictionary(“SheetName”)(“KeyName”)
example two => MasterDictionary(“SheetName”)(“SectionName”)(“KeyName”)

I initially figured MasterDictionary(of String, Dictionary(of string, Dictionary(of String, String)
this would solve example two, however I am then unable to resolve example one.

I then tried MasterDictionary(of String, Object); however this would only work so far…
e.g. example one => MasterDictionary(“SheetName”) would then produce a Dictionary(of String, String for the object portion and I couldn’t use MasterDictionary(“SheetName”)(“KeyName”)

I have been reading the forums, vbnet forums and c# forums trying to figure out how to achieve this.

ideally I would like it to be similar to getting info from a JSON Object

any advise or solutions would be greatly appreciated. Thank you

Hi @K_Morgan

If i understand correct first one is having two levels and second 3… so should it be like MasterDictionary(of String, Dictionary(of String, String)) this?


it would be
dictionary(string, dictionary(of string, string) for most
excel file = dictionary (sheet (string), dictionary (string (key (range a)), string (value (range b)))
but also
excel file = dictionary (sheet (string), dictionary(string (subDictionary index name) , dictionary (string (key (range a)), string (value (range b)))

so I need a dictionary that can handle string, dic (string, string) but also string, dic(string, dic(string, string)

individually I can make these, but I cannot figure out how to add them all into one dictionary

in other languages I can do this in minutes, but because the data type must be set beforehand I cannot figure this out.

Ideally I want to be able to call values like this

ConfigDic(“section”)(“key1”) and ConfigDic(“section”)(“subsection1”)(“key1”)

I have attached my test excel file.
configFile.xlsx (18.2 KB)

Hi @K_Morgan

I understand your situation now I beleive. So for this if you use object in the second level then i beleive because dict structure is not defined you are unable to add the 3rd dict. Why not convert your options to 3 layers for both

Maindic(of string,subdict(of string,dict(of string,string))) will be your final one

For first model use dict(sheet)(key1)(key1)

For second use dict(sheet)(sub1)(key1)

Just replicate your first key twice that creates a mock 3 layer of your two layers