+ Reply to Thread
Results 1 to 9 of 9

Pushing the object within the object question

  1. #1
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    180

    Pushing the object within the object question

    My end goal is to be able to write the following code and have it work for reading data into and out of the object (Ptr2FieldData). I should point out that Coordinates is a property of Ptr2FieldData and is an object.

    Ptr2FieldData.Coordinates.X

    Here is what I am currently doing which is a step in the right direction, but does not get me to my goal. Thanks to xlNitWit, the code works:

    Please Login or Register  to view this content.
    But if I attempt to consolidate the code, the compiler complains with error ‘91’ object variable not set. I know I must be misunderstanding something….please offer insight.
    Please Login or Register  to view this content.
    Here is a shortened Ptr2FieldData Class containing only the critical Coordinate Property
    Please Login or Register  to view this content.
    And here is the CoordinatesClass

    Please Login or Register  to view this content.

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Pushing the object within the object question

    Hi again,

    If you have not assigned a CoordinatesClass object to the property, you cannot write to that object's properties.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Pushing the object within the object question

    So are the lower case x,y different?
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    180

    Re: Pushing the object within the object question

    Hi xlNitWit!

    thank you for replying.

    You stated that "IF YOU HAVE NOT ASSIGNED A COORDINATECLASS object to the property, you cannot write to that object's properties.

    I thought I had done that. Look at "MeasurementClass" which is the class I used to instantiate Ptr2FieldData. I assign Coordinates as a CoordinateClass using the "set" instruction you told me about in the earlier question.

    Am I missing something? Remember I am a novice so if you can readily see my mistake and I can not, please be patient.
    thank you,

    bil

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Pushing the object within the object question

    Your first piece of code creates a CoordinatesClass object and assigns that to the Coordinates property of your object, which is correct. Your second piece of code never creates a CoordinatesClass object but merely tries to assign properties of a non-existent object. If you step through the code you should see that your second version only calls the Get property, which will return Nothing as you never set the property initially.

    I do not really understand why you don't simply use the working code you have.

  6. #6
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    180

    Re: Pushing the object within the object question

    Ok, xlNitWit.....I think I am understanding you. I apologize for taking so long.
    As you know I am 72 and so sometimes I am not intellectually all there. Sorry.

    If I am understanding you correctly,the first piece of code
    explicitly declares(Dim) and instantiates(new) a
    FieldDataCoordinates object. Also, a pointer (reference) to
    that object is defined (set).

    The FieldDataCoordinates property,X, expects a double to be
    storied in it. That data type is the data type found in the
    appropriate worksheet cell. The FieldDataCoordinates object
    is filled with data via the equals sign.

    That declared and instantiated and filled object,
    FieldDataCoordinates, can then be written into the Coordinate
    property of the Ptr2FieldData object which expects at least
    a declared and instantiated object for that property.

    I think that just about wraps up my understanding of your explanations on
    how I could get my code to work.



    You asked me why I simply did not use the working code I already had in place.

    The big picture answer is this:
    * the code as originally written encapsulates Ptr2FieldData in a clear fashion.
    It holds:
    * a measurement ID of type long
    * a measurement elevation of type double
    * a measurement type of type string
    * measurement coordinates of type object
    each of the above properties were intended to be the major categories of any
    Ptr2FieldData object.

    *But with your help, I began to appreciate that if a property is going to be
    an object, that object has to be declared and instantiated EXTERNAL to the
    Ptr2FieldData object.

    That means I lose encapsulation. I place a burden on the code using the
    Ptr2FieldData object to not only know something about coordinates.but to also
    include code necessary to use it (declare and instantiate code)

    So my question was really about trying to find a way around this dilemma.

    Encapsulation of high level abstractions (as represented by an object) necessarily
    shifts knowledge of lower level abstractions that will make up the higher level
    abstractions to the code using the high level abstractions.

    It seems if I want to preserve encapsulation, I need to make an object interface
    take in the lowest abstraction level information and output the highest level info.

    any ideas?

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Pushing the object within the object question

    First may I ask why exactly you need a separate class simply to hold two values?

  8. #8
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    180

    Re: Pushing the object within the object question

    Good Morning xlNitWit !!!!!

    I should mention that my Dad was from England. Always meant to go back to my roots, as my brother and sister described it as feeling as if they were returning home.

    You asked why "exactly" did i feel a need for a separate class simply to hold two values.

    In fact, I don't. I could have written the measurement class with two properties (one for each coordinate) rather than one property (holding the two coordinates).

    I can give you the two reasons I gave myself to justify my decision:
    * I wanted to have all the properties of the measurement class at the same abstraction level.
    Ie: Measurement.ID
    Measurement. Type
    Measurement. Elevation
    Measurement. Coordinates

    all the above properties seemed to me to be on a single abstraction level. By changing the coordinates property to
    Measurement.Coordinate_X
    Measurement.Coordinate_Y
    made my coding easier, but it grated me that now all the properties were not at the same abstraction level.
    I know....I know...seems ludicrous....but that was what was going on in my mind.

    SEcondly.....
    I loved the idea of writing a line of code as: Measurements.coordinates.x
    that line just seemed so clear and hierarchical. to me that line of code meant:
    x is the variable of interest....is a property of a coordinate object
    which is a property of a Measurement object
    it was music to my sensibilities.

    But I found out the hard way that to maintain my desire for same level abstractions for Measurement Properties meant that calling code now had to deal with detail which it really should not have had to address (ie putting x and y values into a coordinate object which then in turn are put into the measurement object).

    so, for now, I am just biting the bullet to retain the Measurement property equal abstraction level objective. No rational argument. Purely emotional? But I certainly see the cost of that decision.

    I welcome all questions as to why I am doing something. It helps me see more clearly what decisions I may be making and not know I am making !!!!! Always feel free to challenge anything. I don't need to win. But I do need to be aware.

    Thank you for helping me, xlNitwit....you have certainly been more than gracious and incredibly patient.
    bil
    Last edited by whburling; 06-04-2017 at 11:45 AM.

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Pushing the object within the object question

    I completely understand your logic but in practical terms, unless you plan to do something with the co-ordinate pairs as a single entity, there is no real practical benefit to the approach.However, you might initialize the PMeasurementCoordinates variable in the Class_Initialize event of your Ptr2FieldData class. That way there will be an object ready for you to assign the X and Y values to by default.

+ 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] Strange 'object invoked disconnected' then '1004 - object defined' errors
    By sumdumgai in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-14-2015, 09:48 PM
  2. Find in VBA finds first instance of similar object being searched but not exact object
    By xcelnovice101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-14-2015, 01:10 PM
  3. Replies: 0
    Last Post: 06-19-2014, 02:09 PM
  4. In Procedure: When use Actual Range Object vs Create Local Object Using Set
    By Filibuster in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-20-2012, 02:21 PM
  5. Replies: 12
    Last Post: 06-20-2012, 01:53 PM
  6. Replies: 3
    Last Post: 10-25-2011, 02:12 PM
  7. buggy macro 'intersect' of object of object'_global failed" when deleting rows
    By Kezwick in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-18-2011, 07:11 AM

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