{"id":526,"date":"2011-11-29T10:16:46","date_gmt":"2011-11-29T09:16:46","guid":{"rendered":"http:\/\/www.capri-soft.de\/blog\/?p=526"},"modified":"2011-11-29T10:29:02","modified_gmt":"2011-11-29T09:29:02","slug":"vba-dictionary-hashmap-assoziatives-array-erstellen","status":"publish","type":"post","link":"https:\/\/www.capri-soft.de\/blog\/?p=526","title":{"rendered":"VBA: Dictionary \/ HashMap \/ assoziatives Array erstellen"},"content":{"rendered":"<h1>Aufgabenstellung<\/h1>\n<p>Wenn es nicht m\u00f6glich ist, Werte nach einem fortlaufendem Index (Ordinalskala) zu klassifizieren, da keine wirklich logische Reihenfolge existiert, kann man auf assoziative Array\/HashMaps oder Dictionaries (synonyme Bezeichnung f\u00fcr nominell skalierte Merkmale) zur\u00fcckgreifen. Dies ist in der Regel aussagekr\u00e4ftiger als ein Index. Diese Datenstruktur bietet beim Zugriff auf ein Element eine sehr hohe Performance. Bei einem Index m\u00fc\u00dfte man alle Elemente der Datenstruktur durchlaufen um einen geeigneten Schl\u00fcssel zu finden.<\/p>\n<h1>Ansatz<\/h1>\n<p>Da VBA nativ keine solche Datenstruktur bes\u00edtzt, wird auf Microsoft Scripting Runtime Object Library (scrrun.dll) zugegriffen. <\/p>\n<h1>Vorraussetzungen<\/h1>\n<p>Die DLL Datei hierf\u00fcr wird automatisch ab Office 2000 mitinstalliert. Im VBA Editor muss unter &#8222;Tools -> Verweise\/References&#8220; die Microsoft Scripting Runtime option angehakt werden. <\/p>\n<h1>L\u00f6sung<\/h1>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n   Dim dictio As Object\r\n   Dim dictioItem As Variant\r\n    \r\n   Set dictio = CreateObject(&quot;scripting.dictionary&quot;)\r\n   dictio.Add &quot;key1&quot;, &quot;value1&quot;\r\n   dictio(&quot;key2&quot;) = &quot;value2&quot;\r\n   dictio(&quot;key3&quot;) = &quot;value3&quot;\r\n\r\n   MsgBox &quot;-&quot; &amp; dictio(&quot;gibtsnich&quot;) &amp; &quot;-&quot;\r\n   Dim i As Integer\r\n   i = 1\r\n   For Each dictioItem In dictio\r\n      If dictio(dictioItem) = &quot;&quot; Then Cells(i, 14).Value = &quot;ich sagte das gibts nich&quot;\r\n      Cells(i, 12).Value = dictioItem\r\n      Cells(i, 13).Value = dictio(dictioItem)\r\n      i = i + 1\r\n   Next\r\n<\/pre>\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.capri-soft.de%2Fblog%2F%3Fp%3D526&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px;margin-top:5px;\"><\/iframe>","protected":false},"excerpt":{"rendered":"<p>Aufgabenstellung Wenn es nicht m\u00f6glich ist, Werte nach einem fortlaufendem Index (Ordinalskala) zu klassifizieren, da keine wirklich logische Reihenfolge existiert, kann man auf assoziative Array\/HashMaps oder Dictionaries (synonyme Bezeichnung f\u00fcr nominell skalierte Merkmale) zur\u00fcckgreifen. Dies ist in der Regel aussagekr\u00e4ftiger als ein Index. Diese Datenstruktur bietet beim Zugriff auf ein Element eine sehr hohe Performance. &hellip; <a href=\"https:\/\/www.capri-soft.de\/blog\/?p=526\" class=\"more-link\"><span class=\"screen-reader-text\">VBA: Dictionary \/ HashMap \/ assoziatives Array erstellen<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[3,12],"tags":[],"class_list":["post-526","post","type-post","status-publish","format-standard","hentry","category-programmierung","category-vba"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4yGeN-8u","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=526"}],"version-history":[{"count":6,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/526\/revisions"}],"predecessor-version":[{"id":532,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/526\/revisions\/532"}],"wp:attachment":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}