Dictionary object returning keys before they are added

  • I am using a dictionary object from the MS Scripting Runtime library to store a series of arrays and perform operations on the array cells as necessary. There is a for loop to go through the process of creating all of these entries. My issue is that when using the .exists property, it is returning a True even before the item has been added. Closer debugging indicates that the key is being added to the dictionary at the beginning of the for loop, even though no .add command is used and will not be used until the end of the loop. The result is that the values in the arrays do not totalize as intended.


    Code for the dictionary build has been included below. I have attached the Excel file which contains the appropriate module which calls that function




    My apologies for the previous post, as the pared down excel file which I posted had a slight error which prevented it from running

  • Re: Dictionary object returning keys before they are added


    I downloaded your sample workbook and tested it. It appears that the Add is treating the ProtoElement as two separate items with the same key instead of as 1 object. You might try to force ProtoElement to an actual array rather than a Variant but I don't know if that will do anything or not. I can't find any reference to what the Dict.Add method does with different item types. I will keep looking and maybe test a couple of ideas. I will let you know what I find.

  • Re: Dictionary object returning keys before they are added


    Thank you vwankerl,


    I have since tried a few different implementations, and it appears that any time that I use that dictionary object, the items are being added before I .add them. Of course this suggests an error in the way that I am implementing them, but they are fairly simple and I believe that I am following the examples faithfully. Here is another, slightly different example.



    For each cell, the first conditional statement is returning a false (key does exist) despite the fact that the dictionary is new. I am completely bumfuzzled.


    Thanks,


    riddley

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!