+ Reply to Thread
Results 1 to 11 of 11

I am having a problem setting an object property which is itself an object

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

    I am having a problem setting an object property which is itself an object

    I am having a problem setting an object property which is itself an object.
    Can someone help me understand the error. Perhaps I am not understanding how to use objects in objects

    Here is the code in which the attempt is made to set the property. The green font is explanatory text.
    The orange text is where I set the properties of a CoordinatesObj. That code works.
    The code red text fails in the setting of the property in the object pointed to by Ptr2FieldData

    Below this code, after the asterics, is the code of the object, MeasurementObj in which the code fails with a run time error (Run-time error ‘91’ Object variable or with block variable not set). I have used red text to indicate the exact line of code that is failing within MeasurementObj



    for as many Measurements exist in FieldData
    With Ptr2OpnWrkBk
    With Ptr2FDWrkSht
    For Row = DataRowStart To NumofRows
    ' instantiate a Measurement Obj
    Set Ptr2FieldData = New MeasurementObj '
    ' instantiate a coordinates obj
    Set FieldDataCoordinates = New CoordinatesObj
    ' read MeasurementData into the MeasurementObj
    Ptr2FieldData.ID = Ptr2FDWrkSht.Cells(Row, ElevationIDColumn).value
    FieldDataCoordinates.X = Ptr2FDWrkSht.Cells(Row, X_CoordinateColumn).value
    FieldDataCoordinates.Y = Ptr2FDWrkSht.Cells(Row, Y_CoordinateColumn).value
    Ptr2FieldData.Coordinates = FieldDataCoordinates
    Ptr2FieldData.Elevation = Ptr2FDWrkSht.Cells(Row, ElevationColumn).value
    Ptr2FieldData.ElevationType = Ptr2FDWrkSht.Cells(Row, ElevationTypeColumn).value
    ' add Ptr2FDo to FieldDataCollection
    Call Ptr2FDc.Add(Ptr2FieldData)
    Next
    End With
    End With

    Option Explicit
    ' MeasurementObj

    Private PMeasurementID As Long
    Private PMeasurementElevation As Double
    Private PMeasurementElevationType As String
    Private PMeasurementCoordinates As CoordinatesObj



    Public Property Let ID(value As Long)
    PMeasurementID = value
    End Property
    Public Property Get ID() As Long
    ID = PMeasurementID
    End Property


    Public Property Let Elevation(value As Double)
    PMeasurementElevation = value
    End Property
    Public Property Get Elevation() As Double
    Elevation = PMeasurementElevation
    End Property


    Public Property Let ElevationType(value As String)
    PMeasurementElevationType = value
    End Property
    Public Property Get ElevationType() As String
    ElevationType = PMeasurementElevationType
    End Property


    Public Property Let Coordinates(value As CoordinatesObj)
    PMeasurementCoordinates = value
    End Property
    Public Property Get Coordinates() As CoordinatesObj
    Coordinates = PMeasurementCoordinates
    End Property

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: I am having a problem setting an object property which is itself an object

    Your post does not comply with Rule 3 of our Forum Rules: Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

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

    Re: I am having a problem setting an object property which is itself an object

    Dear Jeff,

    I am very interested in satisfying your request.

    However, when I click on edit, my post does not appear in the edit window. so I am unable to satisfy your request. Please
    help me meet your demands.

    Also, when I was originally composing my message, I chose to preview my post . I could not find a way to get back to
    the edit mode in order to chose the alternate of posting.

    Also.....the composing window leaves the user with the impression that I can color text. the composing application did in fact imbed control codes to make that happen. they appeared to have been lost in moving my post into an actual posting.

    I look forward to hearing from you. If i don't, I will rewrite my post and post again WITH TAGS....

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: I am having a problem setting an object property which is itself an object

    I agree. I've noted this inability to see the original in order to edit it in other posts recently.
    I've just tried to edit for you and encounter the same problem.

    @Jeff
    Would you see if you have the same problem please. If so I'll flag it with Jerry and Ford.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

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

    Re: I am having a problem setting an object property which is itself an object

    If posting code please use code tags, see here.

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

    Re: I am having a problem setting an object property which is itself an object

    I have figured out the problem.

    When passing an object into another, the receiving object will have code similar to:

    /code at top of class module
    Private PMeasurementCoordinates As CoordinatesObj
    /end code at top of class module

    /Code for reading object property
    Public Property Let Coordinates(value As CoordinatesObj)
    PMeasurementCoordinates = value
    End Property
    /end code for reading object property

    The looking at "value" inside of the receiving object indicates
    the object is making it into the receiving object.

    HOWEVER, in the above example, the reference, "PMeasurementCoordinates"
    is not a valid reference. To make it a valid reference, the code had to be changed

    /code
    Public Property Let Coordinates(value As CoordinatesObj)
    Set PMeasurementCoordinates = value
    End Property
    /end code

    I wish I understood what "set" is actually doing here. perhaps it is "set" sets a pointer to the object in "value"
    thus preserving the original coordinates object and refering to it only through a pointer. Just my best uneducated guess

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: I am having a problem setting an object property which is itself an object

    Quote Originally Posted by Richard Buttrey View Post
    @Jeff
    Would you see if you have the same problem please. If so I'll flag it with Jerry and Ford.
    Richard, I'm seeing it too. I see this occasionally on some threads. Thanks.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: I am having a problem setting an object property which is itself an object

    whburling, now that you have been reminded that we require code tags, please put them in new posts. This is not a "demand," it's one of our rules.

    Put [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] after. You can highlight your code and press the # button to insert both tags automatically.

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: I am having a problem setting an object property which is itself an object

    I am finding the code extract you provided a little confusing out of context. It looks like you have provided code from at least two separate modules in your first post, and you are talking about a Class, not just an Object. It would help a lot if you just attached your file.

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

    Re: I am having a problem setting an object property which is itself an object

    hey 6stringjazzer,

    Imagine having a difficult time with a riff (of music). You are mystified as to why the riff does not work.
    Does it make sense if you present the entire piece of music in asking your question, or does it make sense
    to focus only on the riff.

    In the future I will present the entire code, but i was worried that i was detracting from the focal point of interest.

    thank you for responding.

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: I am having a problem setting an object property which is itself an object

    Imagine having a difficult time with a riff of music. It's a one-measure lick in A minor. You are mystified as to why the riff does not work. You ask experts far and wide and they all say that this riff sounds mighty fine to them. What you did not tell them is that the tune is in Bb major.

+ 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. Replies: 0
    Last Post: 06-19-2014, 02:09 PM
  2. 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
  3. Object required problem when reading interior.color property
    By darry in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-11-2013, 10:55 AM
  4. [SOLVED] problem defining quote sign " in formula property applied to range object
    By mnjofra in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-07-2012, 05:18 PM
  5. Replies: 2
    Last Post: 07-23-2009, 04:49 AM
  6. Range object/property problem.
    By mjsheen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-02-2009, 03:21 AM
  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