Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I create a Dictionary of Dictionary objects? 1

Status
Not open for further replies.

j0em0mma

Programmer
Joined
Jul 31, 2003
Messages
131
Location
US
How would I create a "dictionary" of dictionary objects in ASP? I'm not sure if that's exactly what I need...

What I want to do is be able to add as many dictionaries as I want to an object, then refer to that obect as follows:

MyFirstValue1 = oMyObject.oDictMyDictionary1("MyFirstKey1")
MyFirstValue2 = oMyObject.oDictMyDictionary2("MyFirstKey2")

is this possible?
 
You look like your on the right track with that, here's an example I threw together that will make 3 sub dictionaries, add them to a main dictionary, then loop through all of the embedded dictionaries outputting their values:
Code:
<%
Dim a, b, c, main
Set a=Server.CreateObject(&quot;Scripting.Dictionary&quot;)
Set b=Server.CreateObject(&quot;Scripting.Dictionary&quot;)
Set c=Server.CreateObject(&quot;Scripting.Dictionary&quot;)
Set main=Server.CreateObject(&quot;Scripting.Dictionary&quot;)

a.Add &quot;cat&quot;,&quot;A Cat Item&quot;
a.Add &quot;dog&quot;,&quot;A Dog Item&quot;
a.Add &quot;goat&quot;,&quot;A Goat Item&quot;

b.Add &quot;red&quot;,&quot;A Red Item&quot;
b.Add &quot;blue&quot;,&quot;A Blue Item&quot;
b.Add &quot;green&quot;,&quot;A Green Item&quot;

c.Add &quot;Bread&quot;,&quot;A Bread Item&quot;
c.Add &quot;Meat&quot;,&quot;A Meat Item&quot;
c.Add &quot;Cheese&quot;,&quot;A Cheese Item&quot;

main.Add &quot;Dict_A&quot;,a
main.Add &quot;Dict_B&quot;,b
main.Add &quot;Dict_C&quot;,c

Dim main_key, key, value

For Each main_key in main.keys
	For Each key in main.item(main_key).keys
		Response.Write &quot;Dictionary (&quot; & main_key & &quot;) ==&gt; Item (&quot; & key & &quot;) = &quot; & main.item(main_key).item(key) & &quot;<br>&quot;
	Next
Next
%>

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Awesome! thx Tarwn, that's exactly what I've been looking for! BTW, this, or related, questions have come up previously in this forum, but I couldn't find the answer... Kudos!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top