PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2019 [RESOLVED] Is it possible to nest properties ?-VBForums
Results 1 to 6 of 6

Thread: [RESOLVED] Is it possible to nest properties ?

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2018
    Posts
    38

    Resolved [RESOLVED] Is it possible to nest properties ?

    In this case I have a point (HexLocation) which I want to get/set as property for my class.
    VB.NET Code:
    1. Private HexLocation As Point
    2.  
    3.     Public Property Location As Point
    4.         Get
    5.             Return HexLocation
    6.         End Get
    7.         Set(HexLocation As Point)
    8.         End Set
    9.     End Property
    Then this works just fine afterwards:
    VB.NET Code:
    1. Hexagon1.Location = New Point(0, 0)
    The problem comes when trying to modify only one of those two values, for example:
    VB.NET Code:
    1. Hexagon1.Location.X = 33
    "This expression is a value and cannot be the target of an assignation."
    So I then tried nesting properties but created a demon:
    Name:  Nesting.PNG
Views: 148
Size:  8.1 KB
    This didn't work either:
    Name:  Nesting2.PNG
Views: 147
Size:  8.3 KB
    I can't simply have it as a public variable because I need to execute code when it is modified but not enough for it to require a method, I think, so I'm lost.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,417

    Re: Is it possible to nest properties ?

    The Point data type is a Structure, and therefore cannot be edited. Instead you need to replace it with a whole new value, eg:
    Code:
        Public Property X As Integer
    ...
            Set(NewX As Integer)
                HexLocation = New Point(NewX, HexLocation.Y)
            End Set

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2018
    Posts
    38

    Re: Is it possible to nest properties ?

    Thanks for the tip, that would work great except it would be acessible this way:
    VB.NET Code:
    1. Hexagon1.Location = New Point(0, 0)
    2. Hexagon1.X = 33
    But I would want X to be a member of Location as such:
    VB.NET Code:
    1. Hexagon1.Location = New Point(0, 0)
    2. Hexagon1.Location.X = 33

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,417

    Re: Is it possible to nest properties ?

    In that case either create a new Class with similar properties to Point (and use that instead of Point), or possibly call the new property LocationX (and live without the dot).

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2018
    Posts
    38

    Re: Is it possible to nest properties ?

    Thanks I created a structure for it similar to point but with the property blocks I needed.
    Also the last reply got sent twice mb.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,755

    Re: Is it possible to nest properties ?

    Quote Originally Posted by KBConsole View Post
    Thanks I created a structure for it similar to point but with the property blocks I needed.
    Can you show us your code because I don't see how that could work either.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width