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:
FOR i FROM 1 TO 3 DO TEST i CASE 1: strCoord:="x"; CASE 2: strCoord:="y"; CASE 3: strCoord:="z"; ENDTEST IF ((Position1.trans.strCoord) > 0) THEN Position1Base.strCoord:=WorkObject1.uframe.trans.strCoord - Position1.trans.strCoord; ELSEIF ((Position1.trans.strCoord) < 0) THEN Position1Base.strCoord:=WorkObject1.uframe.trans.strCoord + Position1.trans.strCoord; ENDIF ENDFOR
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.