Re: Collection Look Up - By Key in an Excel VBA App.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



What are you trying to do? Normally, once one stores an object in a
collection, you have to *know* the key through some independent process
to retrieve it.

Yes, you can make your example work but it makes little sense. Here's
why.

First, to make it work you should use

c.add obj,obj.key
set obj=c(obj.key)

Why doesn't it make sense? If you get the key from the object, you
already have a variable pointing to the object. Why bother retrieving
it from the collection?

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article <1137645412.673013.205610@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
vmegha@xxxxxxxx says...
> Hi,
>
> I have used a collection to store a set of Objects that I need to look
> up by the Key value...
>
> Like
>
> Dim c As Collection
> Set c=New Collection
> c.Add Obj, Obj.Key
>
> Neither of these seem to work-
> Key = c(Obj.Key)
>
> Or
>
> Key = c.Item(Obj.Key)
>
> Although the help on the VBA Collection object behaviour seems to
> support either of these two types of Look Up.
>
> Is there some Version / Application Dependency that i might be mnissing
> here?
>
> Also I had to replace the collection with a dictionary for this to
> work. My observation has been that "Add" into a Dictionary is slower
> compared to a collection. The Lookup I havent been able to compare,
> since I havent been able to Look up an Obj by key from a collection.
>
> Help / Ideas, Please?
>
> Thanks in Advance,
> Megha.
>
>
.



Relevant Pages

  • Re: Interpretation of ANOVA when the entire population is under study
    ... > from all stores and to make things simple assume that there are only 2 ... "Generalizations" is the key word. ... then it is silly to compare raw sales. ... Now, you know that the customers are different, the ...
    (sci.stat.consult)
  • Re: Date.equals() bug?
    ... No, I retrieve the date value using the RecordSet.getDatemethod, ... I compare this with the Date object as it ... > your database have special rules for logical comparison ... convert to String in the format yyyy-MM-dd) ...
    (comp.lang.java.programmer)
  • Re: Generic Collection
    ... I would probably end up with a package for each, ... Colour to a Schema! ... compare two collections. ... into comparing the thing that the collection stores. ...
    (comp.lang.ada)
  • Re: OT Re: CA Governor Jerry Brown off to a bad start
    ... No - if you compare the NY suburbs with the suburbs of other cities. ... have most other big-box stores now. ... shopping, thrift stores, cheap electronics stores, dive bars, cheap ...
    (rec.gambling.poker)
  • Re: Filter/ combine data
    ... with data assumed within Sheet1 in cols A and B, ... Copy down to retrieve the addresses from Book2's col B ... of addresses for the stores that have ordered from us in the last year. ... How do I take the information in workbook 2 and make it only show the stores ...
    (microsoft.public.excel.misc)