+ Reply to Thread
Results 1 to 10 of 10

setting an object's property to an object

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

    setting an object's property to an object

    WHEN SETTING AN OBJECT'S PROPERTY TO AN OBJECT
    runtime code fails to work, but no compiler error.

    Here is the code that correctly reads the cells of a worksheet
    and successfully places the values into an object (verified via debugger)

    Please Login or Register  to view this content.

    Here is the line of code that seeks to place the above object,FieldDataCoordinates,
    into an object,Ptr2FieldData,

    Please Login or Register  to view this content.
    The above line executes. I can single step it through the "let" code in the Ptr2FieldData object:

    Please Login or Register  to view this content.

    When the above read code completes execution, the debugger
    reveals the CoordinatesObj DID make it into the private storage of
    the Coordinates property

    but the debugger gives me the impression that it is not there by
    indicating the public property of Ptr2FieldData.Coordinates does not exist
    "object variable....not set"

    Soooo....the code for reading the private data out must be at fault. I used "set" to define PMeasurementCoordinates.....do i have to something analogous in removing Coordinates?

    Please Login or Register  to view this content.
    What does that debugger error message mean? the code did execute.
    Last edited by whburling; 05-30-2017 at 05:48 PM. Reason: learned additional info

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,658

    Re: setting an object's property to an object

    I'm not sure what the problem is, but i have seen cases when variables are named using a VBA keyword like value can produce strange results. I recommend you change the value variable name. That may or may not address your problem.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: setting an object's property to an object

    If it says the variable isn't set, then I'd look at the assignment statement. Which line was highlighted (if any)?
    Last edited by leelnich; 05-30-2017 at 03:16 PM.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: setting an object's property to an object

    I expect PMeasurementCoordinates is not an object, it's an instance of a user-defined type, so the Set should be replaced by Let (or removed).
    Entia non sunt multiplicanda sine necessitate

  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: setting an object's property to an object

    Hi,

    If FieldDataCoordinates / CoordinatesObj is an object, you should use a Property Set and not a Property Let
    Please Login or Register  to view this content.
    and therefore
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

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

    Re: setting an object's property to an object

    leelnich,

    there is not line highlighted. the code fails to extract coordinates from the object and goes immediately to the end of the
    main program. Does not stop anywhere.

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

    Re: setting an object's property to an object

    SHG,

    I checked to see what PMeasurementCoordinates is:

    "Private PMeasurementCoordinates As CoordinatesClass" thus is not PMeasurementCoordinates declared as an object?

    Here is the class:
    Please Login or Register  to view this content.

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

    Re: setting an object's property to an object

    XLnitwit.....
    Thank you so much....your answer worked.
    the key to my problem lay in my error:
    Please Login or Register  to view this content.
    which I corrected at your suggestion to :
    Please Login or Register  to view this content.
    Thank you.

    now your other suggestion....interestingly worked with let as in my original posting:
    Please Login or Register  to view this content.
    and it worked with your suggestion
    Please Login or Register  to view this content.
    can you help me understand what the "set" does in the line:
    Please Login or Register  to view this content.
    I thank you again. ......

  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: setting an object's property to an object

    Truth be told, it is largely convention that one uses a Set property procedure with objects (even Microsoft doesn't always do so however). If you use a Property Set, you must use Set when assigning the object to the property; if you use Property Let, you do not use Set when assigning the object to the property. You can, of course, declare both a Property Let and a Property Set if you so wish so that either syntax will work when assigning the object.

    I am not entirely clear what your original issue was since the code in your original question seems to have changed since first posted.

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

    Re: setting an object's property to an object

    xlnitwit,

    For sure your code suggestions work. I am using both recommendations. I am very grateful you gave me your valuable time and stuck with my efforts to understand. My code works.

    Thank you once again. You were ultra clear. Your assessment accurate. your suggestions helped me as you took the time
    to actually write code using the same variables I was using...so your code made it easy for me to see what you were conveying to me.

    Thank you.

+ 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. I am having a problem setting an object property which is itself an object
    By whburling in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-29-2017, 03:39 PM
  2. Object Does not support property
    By Biplab1985 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-18-2016, 05:28 PM
  3. Replies: 0
    Last Post: 06-19-2014, 02:09 PM
  4. How do you use the Name property of the Range object?
    By Excel_vba in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-15-2013, 07:42 PM
  5. Values property of the Borders Object
    By Excel_vba in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2013, 10:15 PM
  6. Using the Parent property of the Borders Object
    By Excel_vba in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2013, 09:53 PM
  7. Using The Value property of the ActiveCell object
    By Almamba in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-21-2005, 02:06 PM

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