RobotStudio event

dynamic target selection

edited October 2019 in RAPID Programming
I want my program to select a specific target, based on the values of an array.
Short Example:
Proc SelectTarget<br>  FOR i FROM 1 TO X DO<br>    If array{i}=1 THEN<br>      target:=%anothertarget+i%;<br>      !command to exit for loop?<br>    ENDIF<br>  ENDFOR<br>ENDPROC<br>
anothertarget1, 2, 3, .... are predefined targets.

I also tried
but that didnt work either

What should be the right syntax here?
And is it possible to exit the for loop when if condition is set?


  • soup
    soup ✭✭✭
    Think you're looking for GetDataVal and SetDataVal -- check them out in the Rapid Manual.
  • Not 100% sure on this but possibly try the following.....
    Use the TEST and CASE method instead of using the IF statement. Also, use the "RETURN;" command or maybe just set "i:=0 after the condition has been set"  
  •       firstpoint := "p" + NumToStr(i,0);
          GetDataVal firstpoint, target{i};

    You can Return, I think or (a little more hacky) GOTO out of FOR NEXT.  Or make into a WHILE DO.

    Lee Justice
  • SomeTekk
    edited October 2019
    Here's another hackarific way:

    VAR num nArrayPos
    VAR robtarget pTempTarget
    CONST robtarget pArray{##}:=... ;

    WHILE DInput(di_finished)=0 DO
            MoveL pTempTarget, v1000, fine, t_yourTCP \WObj:=wobjyours;
            Incr nArrayPos;

    Regarding the 'late binding' ...  target:=%"anothertarget"+NumToStr(i)%;   From the RAPID overview manual, "Note that the late binding is available for procedure calls only..."  

    Post edited by SomeTekk on
  • Thanks for all the answers,

    GetDataVal was just the right thing i was looking for. :)

    Have a nice day