+ Reply to Thread
Results 1 to 12 of 12

Scripting.Dictionary Question

  1. #1
    Registered User
    Join Date
    09-19-2012
    Location
    Anaheim, California
    MS-Off Ver
    Excel 2010
    Posts
    22

    Angry Scripting.Dictionary Question

    So I have this code which uses the dictionary object to find unique values in column F. Some of the code was pieced together from internet examples and my current knowledge. I understand how it works except for this line.
    Please Login or Register  to view this content.
    . What does the "= 1" do? Does it matter what that is set to? Any information is appreciated. Below is the full code:

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Scripting.Dictionary Question

    Hello msolari,

    It is assigning the value 1 to the Dictionary key represented by CStr(Range("F" & z))).
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    09-19-2012
    Location
    Anaheim, California
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Scripting.Dictionary Question

    Thanks Leith. What does that mean in the grand scheme of things? Can you conjure that list of values with something like this then?
    Please Login or Register  to view this content.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Scripting.Dictionary Question

    Hello msolari,

    If you want to return an array of either all Keys or Items in the Dictionary, you can do so like this...
    Please Login or Register  to view this content.
    These arrays are 1-D zero based arrays. The first element subscript is zero, i.e. Keys(0).

  5. #5
    Registered User
    Join Date
    09-19-2012
    Location
    Anaheim, California
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Scripting.Dictionary Question

    Ok..kind of understanding here. Sorry I'm new to the dictionary thing. How would you debug.print a single key? Also, can a single key hold multiple strings?

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

    Re: Scripting.Dictionary Question

    Quote Originally Posted by msolari View Post
    Please Login or Register  to view this content.
    You can write like that only if you set the reference to "Microsoft Scripting Runtime".
    e.g
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    09-19-2012
    Location
    Anaheim, California
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Scripting.Dictionary Question

    Thanks jindon, that is enlightening. And answers a few questions for me. But I still have my original question
    Please Login or Register  to view this content.
    What does the "= 1" do? I realize it sets its value to one but what does that let you do? Does it need to be there? Does it matter even what that is set to? Could I have it set to
    Please Login or Register  to view this content.
    Thanks in advance

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Scripting.Dictionary Question

    it just needs to be a value; it doesn't matter what the value is
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  9. #9
    Registered User
    Join Date
    09-19-2012
    Location
    Anaheim, California
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Scripting.Dictionary Question

    So the value at the end does not affect the data stored in the dictionary? It doesn't matter at all what that is set to?

  10. #10
    Registered User
    Join Date
    09-19-2012
    Location
    Anaheim, California
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Scripting.Dictionary Question

    Using code from jindon, I realize now that the "=1" sets the item number for that particular key. Thanks. Makes so much sense now.

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

    Re: Scripting.Dictionary Question

    DXNRY(CStr(Range("F" & z))) = 1
    Let's assume the value of CStr(Range("F" & z)) = "x"

    The line is setting Item property of dictionary for "x" to 1
    In other words, it is equivalent to
    Please Login or Register  to view this content.
    It is not an Index, so 1 could be anything.

  12. #12
    Registered User
    Join Date
    09-19-2012
    Location
    Anaheim, California
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Scripting.Dictionary Question

    THANK YOU THANK YOU THANK YOU!!! You confirmed it. Been staring at this forever. Such a relief

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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