# Use a record and array in routines

**URL:** <https://tech-community.robotics.abb.com/t/use-a-record-and-array-in-routines/7635>\
**Category:** RobotStudio\
**Tags:** array, robotstudio, robotstudio-sdk, rapid-code, rapid\
**Created:** [March 21, 2017, 10:37am UTC](https://tech-community.robotics.abb.com/t/use-a-record-and-array-in-routines/7635 "2017-03-21T10:37:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArneBert](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@ArneBert](https://tech-community.robotics.abb.com/u/ArneBert)\
**Post date:** [March 21, 2017, 10:37am UTC](https://tech-community.robotics.abb.com/t/use-a-record-and-array-in-routines/7635/1 "2017-03-21T10:37:56Z")

</div>

Hello

I’m a student who has a school assignment about a robot and we are using an record array to store our data about different thing like, height, color, position and if the piece is good.  
But we need to make sure are date if modified is transferred to the other routines, but we are having difficulties to use the array in a routine. You can see what we have below:

MODULE MainModule

RECORD Stift  
string strStift;  
bool baanwezig;  
num numkleur;  
num numhoogte;  
robtarget robpunt;  
ENDRECORD

Var Stift stiftarray{5}:=  
[[“stift1”, True, 10, 1000, [[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],  
[“stift2”, false, 200, 20,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],  
[“stift3”, True, 30, 30,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],  
[“stift4”, false, 40, 40,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],  
[“stift5”, true, 50, 50,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]]];  
!CONST robtarget P\_test\_kleur:=[[273.53,322.55,187.08],[0.000164752,0.706799,0.707415,-0.000414261],[0,-1,1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];

PROC main()  
Detectie\_Hoogte\_en\_Kleur stiftarray{5};  
FOR i FROM 1 TO Dim(stiftarray,1) DO  
TPWrite NumToStr(stiftarray.numhoogte,0);  
ENDFOR

ENDPROC

PROC Detectie\_Hoogte\_en\_Kleur (inout num stiftarray{\*})  
FOR i FROM 1 TO Dim(stiftarray,1) DO  
stiftarray{i}.numhoogte:= stiftarray{i}.numhoogte + 40;

!MoveJ stiftarray{i}.robpunt,v20, z50,t\_sensor;

ENDFOR  
ENDPROC

ENDMODULE

Thanks for your help  
Arne Berteloot

---

<div class="post-metadata">

**Author:** ![soup](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/soup/32/1592_2.png) [@soup](https://tech-community.robotics.abb.com/u/soup)\
**Post date:** [March 21, 2017, 7:26pm UTC](https://tech-community.robotics.abb.com/t/use-a-record-and-array-in-routines/7635/2 "2017-03-21T19:26:47Z")

</div>

The array is a global variable, so you can use and edit it without explicitly passing it into a routine. Try calling Detectie\_Hoogte\_en\_Kleur alone in main & remove the need for the INOUT from the Detectie\_Hoogte\_en\_Kleur procedure. Also your TPWrite needs a dimension (I’d assume you meant, "TPWrite NumToStr(stiftarray{i}.numhoogte,0);).

---

<div class="post-metadata">

**Author:** ![ArneBert](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@ArneBert](https://tech-community.robotics.abb.com/u/ArneBert)\
**Post date:** [March 22, 2017, 8:08am UTC](https://tech-community.robotics.abb.com/t/use-a-record-and-array-in-routines/7635/3 "2017-03-22T08:08:57Z")

</div>

Thanks for you"re help. So if we for instance put in the routine Detectie\_Hoogte\_en\_Kleur and put numhoogte to 5 for example, this value leaves the routines also and if we call another routine it would give the same number?  
And yes your correct about TPWrite, my bad 😃

---

<div class="post-metadata">

**Author:** ![soup](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/soup/32/1592_2.png) [@soup](https://tech-community.robotics.abb.com/u/soup)\
**Post date:** [March 22, 2017, 12:54pm UTC](https://tech-community.robotics.abb.com/t/use-a-record-and-array-in-routines/7635/4 "2017-03-22T12:54:35Z")

</div>

The FOR loop of adding 40 to all numhoogte in the array threw me off. If you’re trying to pass just a part of an array, say 5, you could just pass the num to identify it and only add 40 to that entry.

PROC main()  
Detectie\_Hoogte\_en\_Kleur 5;  
FOR i FROM 1 TO Dim(stiftarray,1) DO  
TPWrite NumToStr(stiftarray.numhoogte,0);  
ENDFOR  
ENDPROC

PROC Detectie\_Hoogte\_en\_Kleur (inout num id)  
stiftarray{id}.numhoogte:= stiftarray{id}.numhoogte + 40;  
ENDPROC

---

<div class="post-metadata">

**Author:** ![ArneBert](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@ArneBert](https://tech-community.robotics.abb.com/u/ArneBert)\
**Post date:** [March 22, 2017, 6:20pm UTC](https://tech-community.robotics.abb.com/t/use-a-record-and-array-in-routines/7635/5 "2017-03-22T18:20:16Z")

</div>

Thanks your a great help.

---

<div class="post-metadata">

**Author:** ![ArneBert](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@ArneBert](https://tech-community.robotics.abb.com/u/ArneBert)\
**Post date:** [March 22, 2017, 7:02pm UTC](https://tech-community.robotics.abb.com/t/use-a-record-and-array-in-routines/7635/6 "2017-03-22T19:02:49Z")

</div>

Soup I tried it your way and I got always the same error, this one:

 ![image.png](https://europe1.discourse-cdn.com/flex005/uploads/robotics1/original/2X/9/9e334608911992522d65db3efbad6d9b025b12ac.png)

So I tried with a number as you see below but it still doesn’t work and now I get this error on the dim(stiftarray{numcounter,0}:

 ![image.png](https://europe1.discourse-cdn.com/flex005/uploads/robotics1/original/1X/bcfa0948d5619c984b51bf6ceebcbac3c75173f6.png)

MODULE MainModule

RECORD Stift  
string strStift;  
bool baanwezig;  
num numkleur;  
num numhoogtestift;  
num numoffsethoogte;  
robtarget robpunt;  
ENDRECORD

Var Stift stiftarray{6}:=  
[  
[“stift1”, True, 10, 100, 0, [[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],  
[“stift2”, false, 200, 20,0,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],  
[“stift3”, True, 30, 300,0,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],  
[“stift4”, false, 40, 400, 0,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],  
[“stift5”, true, 50, 500,0,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],  
[“stift6”, true, 60, 600,0,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]]  
];  
!einde array  
!Belangrijke punten  
!Punt voor te testen van kleur  
CONST robtarget P\_test\_kleur:=[[273.53,322.55,187.08],[0.000164752,0.706799,0.707415,-0.000414261],[0,-1,1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];  
!We gaan 3 punten nodig hebben op pallet 1 om volgende zaken te weten: verschuiving in X en y ten opzichte van 2 stiften.  
!We gaan dus 1 stift als centraal punt nemen  
CONST robtarget P\_stift\_positie124:=[[0,-200,nummaxhoogtestift],[1,0,0,0],[0,0,1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];  
!1 stift kiezen die opgeschoven is in de X richting  
CONST robtarget P\_stift\_positie114:=[[50,-200,nummaxhoogtestift],[1,0,0,0],[0,0,1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];  
!1 stift kiezen die opgeschoven is in de y-richting  
CONST robtarget P\_stift\_positie123:=[[0,-220,nummaxhoogtestift],[1,0,0,0],[0,0,1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];

!Maximale hoogte die en stift mag hebben moet lager zijn dan 15cm  
!via deze constante is dit ook makkelijk aan te passen.  
CONST num nummaxhoogtestift:= 150;  
!plaat dikte bepalen en instelbaar  
CONST num numplaat:= 50;  
!gewenste hoogte die we instellen  
CONST num numingestelde\_hoogte:= numplaat + nummaxhoogtestift;  
!effecteive hoogte van stift  
VAR num numeffectieve\_hoogte:=0;  
!variabele voor offsets  
!in x richting  
VAR num numxoffset:=0;  
!in y richting  
VAR num numyoffset:=0;  
VAR num numaantal\_stiften:=6;

PROC main()

Detectie\_Hoogte\_en\_Kleur numaantal\_stiften;

FOR numaantal\_stiften FROM 1 TO Dim(stiftarray{numaantal\_stiften},1) DO

Tpwrite numtostr(stiftarray{numaantal\_stiften}.numkleur,0);

ENDFOR

ENDPROC

PROC Detectie\_Hoogte\_en\_Kleur(inout num numcounter)

FOR i FROM 1 TO Dim(stiftarray{numcounter},1) DO

stiftarray{numcounter}.numkleur:= stiftarray{numcounter}.numkleur + 40;

ENDFOR  
ENDPROC

ENDMODULE

Thanks

---

<div class="post-metadata">

**Author:** ![soup](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/soup/32/1592_2.png) [@soup](https://tech-community.robotics.abb.com/u/soup)\
**Post date:** [March 22, 2017, 9:14pm UTC](https://tech-community.robotics.abb.com/t/use-a-record-and-array-in-routines/7635/7 "2017-03-22T21:14:24Z")

</div>

Sorry – the INOUT is not needed – PROC Detectie\_Hoogte\_en\_Kleur (num id)

---

<div class="post-metadata">

**Author:** ![ArneBert](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@ArneBert](https://tech-community.robotics.abb.com/u/ArneBert)\
**Post date:** [March 23, 2017, 9:07am UTC](https://tech-community.robotics.abb.com/t/use-a-record-and-array-in-routines/7635/8 "2017-03-23T09:07:32Z")

</div>

Now it works great thanks. I can’t thank you enough!!!
