dynamic target selection

PabaPaba Germany
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
target:=%"anothertarget"+NumToStr(i)%;
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?
Tagged:

Comments

  • soupsoup USA ✭✭✭
    Think you're looking for GetDataVal and SetDataVal -- check them out in the Rapid Manual.
  • Bisby_Bisby_ United Kingdom
    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"  
  • lemster68lemster68 United States ✭✭✭
          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
  • SomeTekkSomeTekk USA
    edited October 2019
    Here's another hackarific way:

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

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

    ...
         
    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
  • PabaPaba Germany
    Thanks for all the answers,

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

    Have a nice day
Sign In or Register to comment.