+ Reply to Thread
Results 1 to 4 of 4

accesing class members of an object returned by dictionary item

  1. #1
    Registered User
    Join Date
    04-25-2013
    Location
    toronto
    MS-Off Ver
    Excel 2003
    Posts
    58

    accesing class members of an object returned by dictionary item

    I am perplexed by an error that I have not been able to figure out

    I store an index and an object as a pair in Dictionary object

    dictobj.add i, MyclassA


    where MyclassA is an instance of Myclass

    so I retrieve the value by calling dictobj(i)

    But I find that whatever "friend" properties I have in Myclass I could not directly access them as:
    dictobj(i).k

    if k is declared as friend in Myclass

    However if I first assign dictobj(i) to a variable of type Myclass:

    set A=dictobj(i)

    then A.k is totally legit and the compiler will not complain.

    If I access it by dictobj(i).k the compiler will immediately put up error 438 to complain of "no such method or properties" as if it were not even visible to it.

    I am doing all this within the same project but I am not too sure why it is behaving this way.

    My suspicion is that whatever Dictionary returns as value is still considered as in its own space and it's a kind of variant object (it is not aware of its real type - it really does not care). Since it is an external library that is linked into my main project, it cannot directly access any properties declared as friend. I am not so sure whether this explains what I am seeing.

    However, if I declare K as public the behaviour is no longer observed. It will compile without any complaint at all.

    So dictobj(i).k is perfectly legit again.

    Why declaring public versus friend cause such big difference?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: accesing class members of an object returned by dictionary item

    How/where exactly are you using dictobj(i).k?
    If posting code please use code tags, see here.

  3. #3
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: accesing class members of an object returned by dictionary item

    Friend can't be late bound, which is why you have to declare a variable as the specific class type. (if you declare the variable as Object or Variant it still won't work)
    Remember what the dormouse said
    Feed your head

  4. #4
    Registered User
    Join Date
    04-25-2013
    Location
    toronto
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: accesing class members of an object returned by dictionary item

    Quote Originally Posted by romperstomper View Post
    Friend can't be late bound, which is why you have to declare a variable as the specific class type. (if you declare the variable as Object or Variant it still won't work)
    Thank you so much. Now that resolves the mystery!

+ 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] Code using dictionary class is too slow- need it work faster if possible.
    By strud in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 02-04-2014, 12:09 PM
  2. [SOLVED] accessing members of a class object passed in as variant type?
    By vientito in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2013, 11:21 PM
  3. [SOLVED] Call members from an implemented class
    By baldphil in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2012, 12:35 PM
  4. 2 Dimentional Array as Dictionary Item
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-05-2011, 11:13 AM
  5. Dictionary object: Error assigning user defined data type to item
    By Paul Urbanus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2005, 12:25 AM

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