Results 1 to 3 of 3

Thread: Trouble with assigning the result of a function to a property

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2018
    Posts
    80

    Trouble with assigning the result of a function to a property

    Hi, my issue is that I can't seem to be able to assign a function's return value to an instance of a Class of same type:

    vb.net Code:
    1. Dim MTranslate_Z As Matrix3D = Matrix3D.Create_Scale(2, 2, 2)
    2.  
    3. For Each Vertex As PVector In PTriangle.Vertices
    4.     Dim unused As PVector = MTranslate_Z.MultiplyVector(Vertex)
    5.     Vertex = unused
    6. Next

    More info on the above:

    -PTriangle.Vertices is a property that returns an array of PVector objects.
    -The "MultiplyVector" Function of the matrix returns a PVector object.

    I want to assign the object returned by the function to each object looped trough in the array but it tells me "Unnecessary assignment of a value to Vertex"
    I thought of making it a sub and directly change the PVector but I rather keep it as a function, how should I proceed ?
    Is it in the PVector Class that I need to add something to allow this ?

    Thanks in advance for the help !

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,598

    Re: Trouble with assigning the result of a function to a property

    Vertex is a reference to an object in PTriangle.Vertices.
    If you change Vertex to point to your local instance "unused", that will have no effect on the object in PTriangle.Vertices.
    You want to change the object that Vertex is referencing, which means you want to change the object in PTriangle.Vertices.

    You probably don't want a For Each here, but need to iterate the Vertices collection so you can assign the "unused" reference to the indexed Vertices reference.

    I'm not the expert though, so would have to research the best syntax for this.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Trouble with assigning the result of a function to a property

    Yeahh, you don't want a for each here.... you want a good ol' fashioned For loop... reference the items in the array through their index and assign the result frmo the function to the indexed element directly:
    Code:
    For x as integer = 0 to PTriangles.Vertices.Length-1
       Dim Vertex As PVector = PTriangles.Vertices(x) 
       PTriangles.Vertices(x) = MTranslate_Z.MultiplyVector(Vertex)
    Next
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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
  •  



Click Here to Expand Forum to Full Width