+ Reply to Thread
Results 1 to 12 of 12

Dictionaries and arrays explanation

  1. #1
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Dictionaries and arrays explanation

    I'm trying to improve my understanding of Dictionaries and Arrays (I'm between jobs so I have the time) and I was looking at a piece of code in a response to a thread "generate array from multiple rows" sometime in 2017.

    The answer was provided by Jindon.

    https://www.excelforum.com/excel-pro...le-rows-2.html

    Can anyone explain how the code below works?

    Is there a good tutorial on how to understand how to use Dictionaries and Arrays?

    Please Login or Register  to view this content.
    Regards,
    Xrull
    Last edited by Xrull; 05-29-2019 at 08:06 AM.

  2. #2
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Dictionaries and arrays explanation

    I'm unable to get the code tags to work; it could be a problem with my browser.
    Last edited by AliGW; 05-29-2019 at 07:59 AM.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Dictionaries and arrays explanation

    Before start, you need to wrap the vba code with the code tags.


    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,959

    Re: Dictionaries and arrays explanation

    I have amended them for you. You had added both opening AND closing tags at either end of the code instead of the opening tag at the start and the closing tag at the end.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Dictionaries and arrays explanation

    Xrull,

    The purpose of the code was to fulfill the requirement in the original thread.
    I will import this into SQL via csv and the script reads all fields equally so if the max is 4 data points and one of the rows only has 2 data points, I will need 4 comma delimiters anyway.
    Please Login or Register  to view this content.
    Do a step debug with LocalWindow open, so that you can see all the variables.
    If you still have problem, just point out the line(s) that you don't understand.

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Dictionaries and arrays explanation

    Some more info on Dictionaries and Arrays.

    http://www.snb-vba.eu/inhoud_en.html
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  7. #7
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Dictionaries and arrays explanation

    Jidon

    This is the technique I don't get.

    Please Login or Register  to view this content.
    I've been trying to understand how these work together: This looks like one part .Item(a(i,1)) (2) and this is part two (CStr(a(i,3)))

    I've put it in the watch window, but I get " Expression not defined in context " for the following:

    Please Login or Register  to view this content.
    but it doesn't work unless they are joined.

    The locals window shows what all the variables are, but not how they work in harmony with each other.

    Thanks again

    BakerMan2

    I looked at Snb's site on Sunday and got a better understanding of dictionaries; I worked my way through about 3/4 of the examples; probably it is there somewhere. I'll look at the rest of the examples today.

    Thanks
    Last edited by Xrull; 05-29-2019 at 04:02 PM.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Dictionaries and arrays explanation

    OK, that part is a bit tricky.

    Let me explain about Jagged Array, Arrays in an Array, first.

    Take an example below
    Please Login or Register  to view this content.
    If you look at the Local Window and expand the variable MinArray by clicking + sign, it shows like

    MainArray(1)(1)'<--- John
    MainArray(1)(2)'<--- H
    MainArray(2)(1)'<--- Paul
    MainArray(2)(2)'<--- M
    MainArray(3)(1)'<--- Geroge
    MainArray(3)(2)'<--- H

    This is how it is indexed.
    So, if you want to refer to 1st element of 2nd elements in MainArray
    Please Login or Register  to view this content.
    will give you "Paul" and this is, so you can change it like
    Please Login or Register  to view this content.
    Get back to your question
    When Dictionary stores an array in its item, only object type element can be updated in that way.
    Please Login or Register  to view this content.
    Let's add one variable already delcared, so that it would be easier for you.
    Please Login or Register  to view this content.
    This means w(1) doesn't change and w(2) will add new key when a(i,3) is new and .Item(a(i, 1)) is updated so.

    Further question?
    Last edited by jindon; 05-31-2019 at 08:16 AM.

  9. #9
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Dictionaries and arrays explanation

    Jindon,

    Thanks for the explanation. Give me until weekend absorb and to mark it as solved.

    Regards,
    Xrull

  10. #10
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Dictionaries and arrays explanation

    Based on Jindon's explanation, I understand the jagged array, however, I have a few questions.

    1) How does using "=Empty" in the line below add unique items? I would have thought "Empty" would leave nothing. Probably Nothing and Empty are two different things or Empty means add.

    2) How do I see what the two parts in the .Item() are in the lines below?

    3) How does .Item know how to handle each argument or each piece of the array it precedes.
    Please Login or Register  to view this content.
    I tried emptying the two parts below:

    Please Login or Register  to view this content.
    and I got an error this line:

    Please Login or Register  to view this content.
    It seems it only works like this

    Please Login or Register  to view this content.
    The question is why and how do I find documentation on how .Item(s) operates?

    Still researching -- I'm getting there (I think),

    Xrull.
    Last edited by Xrull; 06-01-2019 at 01:10 PM.

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Dictionaries and arrays explanation

    Hope this answers to your questions.
    Please Login or Register  to view this content.
    Last edited by jindon; 06-01-2019 at 08:37 PM.

  12. #12
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Dictionaries and arrays explanation

    Jindon,

    Thanks for taking the time to explain the various methods on how one can use the dictionary. I'm have a better understanding of how it works. With a little practice I should be able expand the usage of the dictionary for more than creating unique lists.

    If I have anymore questions I'll let know.

    This old dog is learning new tricks.
    Attachment 626897

    Regards,
    Xrull

+ 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] 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
  2. Replies: 5
    Last Post: 11-12-2018, 10:24 PM
  3. [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
  4. Arrays and Collections and Dictionaries oh my
    By JYTS in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-24-2015, 12:06 AM
  5. [SOLVED] Find a specific sum for two different arrays..(more explanation in the post)
    By bach1229 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 10-03-2015, 08:21 AM
  6. [SOLVED] Looking for online learning materials on arrays & scripting dictionaries
    By strud in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-11-2013, 08:16 AM
  7. [SOLVED] Explanation on Arrays
    By NeedForExcel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-02-2013, 06:58 PM

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