Using a Variable to Access a Component of a Record Data Type

  • I'm currently writing a function that will calculate the distance between two robtargets even if they are taught in different work objects. Do to this, the function asks for two positions of data type robtarget, and their respective work objects. Then I do some math to convert the robtarget's trans component to be in reference to the base coordinate system, copy this data into a pos data type, then use the Distance function.


    I wanted to condense my code by using a FOR loop and changing which coordinate of the robtarget's trans component I was manipulating during each pass, like this:

    This creates a syntax error though, as strCoord is not a record component. I tried creating my own record data type and assigning it the different coordinates but I got the same error. I know that the x, y, and z components are not actually strings but I'm not sure how to access the different components without using three sets of IF statements and directly using trans.x, trans.y, and trans.z, if it's even possible.

  • AD
  • As it turns out the math I was doing was incorrect, and I don't even need to do it because I can use built-in functions to accomplish my goals. Still, now I know that something like this is impossible to do for future reference.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account
Sign up for a new account in our community. It's easy!
Register a new account
Sign in
Already have an account? Sign in here.
Sign in Now