Paba
October 8, 2019, 1:01pm
1
I want my program to select a specific target, based on the values of an array.
Short Example:
Proc SelectTarget
FOR i FROM 1 TO X DO
If array{i}=1 THEN
target:=%anothertarget+i%;
!command to exit for loop?
ENDIF
ENDFOR
ENDPROC
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?
soup
October 8, 2019, 3:20pm
2
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.
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…”
Paba
October 9, 2019, 6:44am
6
Thanks for all the answers,
GetDataVal was just the right thing i was looking for.
Have a nice day