<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; VBScript: двухуровневый Dictionary]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=3907</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=3907&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «VBScript: двухуровневый Dictionary».]]></description>
		<lastBuildDate>Sun, 22 Nov 2009 09:46:19 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[VBScript: двухуровневый Dictionary]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=30958#p30958</link>
			<description><![CDATA[<p>Часто возможностей стандартного объекта Dictionary не хватает из-за того, что он одноуровневый. Поскольку в качестве item данного объекта может быть любой иной объект, то напрашивается там хранить другой словарь, тем самым реализуя двух и более уровневые словари. Привожу пример кода для 2-х уровневого варианта:<br /></p><div class="codebox"><pre><code>Set objRootDict = CreateObject(&quot;Scripting.Dictionary&quot;)

arrTest = Array(10,20,30) &#039; в качестве полезной нагрузке будем хранить, например, массив
Add_Element &quot;A&quot;, &quot;1&quot;, arrTest &#039; добавляем элемент в коллекцию
arrTest = Array(40,50,60)
Add_Element &quot;A&quot;, &quot;2&quot;, arrTest
arrTest = Array(70,80,90)
Add_Element &quot;B&quot;, &quot;1&quot;, arrTest
WScript.Echo Get_Element(&quot;B&quot;, &quot;1&quot;)(2) &#039; получаем элемент из коллекции

&#039; Перебор всей коллекции и вывод на экран
For Each dbgMainKey In objRootDict.Keys
    Set objTempDict = objRootDict.Item(dbgMainKey)
    For Each dbgKey In objTempDict.Keys
        arrValueList = objTempDict.Item(dbgKey)
        s = dbgMainKey &amp; vbTab &amp; dbgKey
        For i = 0 To UBound(arrValueList)
            s = s &amp; vbTab &amp; CStr(arrValueList(i))
        Next
        WScript.Echo s
    Next
Next

Sub Add_Element(parLevel_1, parVevel_2, parValue)
    If Not objRootDict.Exists(parLevel_1) Then
        Set objTempDict = CreateObject(&quot;Scripting.Dictionary&quot;)
        objRootDict.Add parLevel_1, objTempDict
    Else
        Set objTempDict = objRootDict.Item(parLevel_1)
    End If
    objTempDict.Add parVevel_2, parValue
End Sub
    
Function Get_Element(parLevel_1, parVevel_2)
    If objRootDict.Exists(parLevel_1) Then
        Set objTempDict = objRootDict.Item(parLevel_1)
        If objTempDict.Exists(parVevel_2) Then 
            Get_Element = objTempDict.Item(parVevel_2)
        Else
            Get_Element = Null
        End If
    else
        Get_Element = Null
    End If
End Function</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (dsb)]]></author>
			<pubDate>Sun, 22 Nov 2009 09:46:19 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=30958#p30958</guid>
		</item>
	</channel>
</rss>
