Forum Migration Notice
We're transitioning to a more modern community platform by the end of this year. Learn about the upcoming changes and what to expect.

Use Iterated User Data Types

Hi.



Need to use numbers in variable names and use them (numbers) in loops. To iterate them.

I have a data type with 10 elements of two-dimensional arrays.
I want to use them to store data from SICK IVC-2D camera  - read/write product's positions.



I decrease no. of elements to 3 to simplify case:





RECORD poseCol

  pose p0, pose p1, pose p2

ENDRECORD



VAR poseCol poseCollection_0;

VAR poseCol poseCollection_1;

VAR poseCol poseCollection_2;





I cannot use array in RECORD statement - so I have to use such a structure.



I need to read/write all elements from all poseCol variables.

I tried to use '%' but I think it works only for PROC:



FOR i FROM 0 TO 2 DO
  %"poseCollection_0.p"+NumToStr(i,0)% := ....;
ENDFOR




Does anybody know solution for such a task?


Furthermore because I cannot use arrays in RECORD statement I cannot use DIM function to make my code more flexible.



Wojciech Wlodarski
PLABB

Comments

  • Have you tried the SetDataVal command, i have used this for a similar situation before. It allows you to build a string and use that to specify the variable name.

  • No, I have not... and I think I should ;)

    GetDataVal and SetDataVal should solve most of the problems.

     

    Thanks!

    BR
    Wojciech Wlodarski
    PLABB