+ Reply to Thread
Results 1 to 4 of 4

Nested Dictionaries with Array as Item ... syntax for looping using For i = 0 to ..., not

  1. #1
    Registered User
    Join Date
    10-11-2018
    Location
    Houston
    MS-Off Ver
    Windows 10
    Posts
    10

    Nested Dictionaries with Array as Item ... syntax for looping using For i = 0 to ..., not

    First time poster ... forgive any violations, please.

    I have been struggling to find the correct syntax for looping (using For i = 0 to ... and NOT using For Each) through nested Dictionaries when the Item in the Inner Dictionary is an Array.
    The code using For Each works fine, but for the life of me, I cannot get the syntax right using For i = 0 to ...

    As you can see in the code below, I have an outer Dictionary and two inner Dictionaries. The two inner Dictionaries each have two String Keys and each Key has one Array as the Item.

    I can easily access the Keys and Items in the outer Dictionary using a series of For Each statements, but when I try to translate that to For i = 0 to ..., I just can't figure out the syntax.
    Specifically, I can't figure out the syntax for the Keys for the inner Dictionary, nor can figure out the looping parameters for accessing the individual Array items. (See the areas in the code near the
    bottom of the code where there is [... can't figure out the syntax ...] text.

    Any help would be appreciated. Thanks in advance.

    Please Login or Register  to view this content.
    Last edited by trhenkel; 07-31-2022 at 05:28 PM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Nested Dictionaries with Array as Item ... syntax for looping using For i = 0 to ...,

    Try this...

    Please Login or Register  to view this content.
    VBA for Smarties has a good Dictionary syntax reference.
    http://www.snb-vba.eu/VBA_Dictionary_en.html
    Last edited by AlphaFrog; 07-31-2022 at 10:11 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    10-11-2018
    Location
    Houston
    MS-Off Ver
    Windows 10
    Posts
    10

    Re: Nested Dictionaries with Array as Item ... syntax for looping using For i = 0 to ...,

    Absolutely fantastic! Worked like a charm!

    Follow-up question: I had gone through VBA for Smarties several times, and saw the syntax (in sections 14.2 and 14.3) but failed to understand how to use that syntax.
    Is the use of the empty () an anomaly or is there a way for me to try to understand what () is meant to mean?

    Thanks so much ... so very much ... for your help. I should have posted earlier. It would have saved me many hours of trial and error.

  4. #4
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,220

    Re: Nested Dictionaries with Array as Item ... syntax for looping using For i = 0 to ...,

    outer.Items() - returns you the first level array
    outer.Items()(i) - you refer to the i-th element of the first level array
    outer.Items()(i).Items() - returns you the array of the i-th element of the first level array (that is, the second level array)
    outer.Items()(i).Items()(j) - you refer to the j-th element of the second array.

    Artik

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Compare two dictionaries or check the 2 part item of a dictionay
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-03-2020, 01:35 PM
  2. [SOLVED] Dictionaries within dictionaries to describe 3 different tables and theirs atributes
    By jaryszek in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-03-2018, 07:21 AM
  3. Error 10 - Locked Array while iterating through dictionaries
    By Pango in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-16-2017, 03:54 PM
  4. [SOLVED] Dictionaries vs Collections: Please help me understand when Dictionaries are better
    By joe31623 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-14-2016, 12:36 PM
  5. [SOLVED] Looping thru arrays with dynamic names. Array1/2/3/5, how to array(Array & i) syntax?
    By graym463 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-24-2015, 10:15 AM
  6. Why do nested dictionaries update retroactively?
    By dmasters4919 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-08-2015, 12:52 PM
  7. VBA. Syntax issue. Looping array
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-11-2012, 10:17 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1