# Generic code with different I/Os

**URL:** <https://tech-community.robotics.abb.com/t/generic-code-with-different-i-os/8492>\
**Category:** RAPID Programming\
**Tags:** solved\
**Created:** [October 2, 2018, 7:17am UTC](https://tech-community.robotics.abb.com/t/generic-code-with-different-i-os/8492 "2018-10-02T07:17:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ko414du4](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@ko414du4](https://tech-community.robotics.abb.com/u/ko414du4)\
**Post date:** [October 2, 2018, 7:17am UTC](https://tech-community.robotics.abb.com/t/generic-code-with-different-i-os/8492/1 "2018-10-02T07:17:32Z")

</div>

Hello,

I have a repeated piece of code in a program but I am stuck with making it ‘generic’ because of different I/O it’s using. A simple version of this is below:

PROC routine1()  
ErrWrite\I,“Starting..”,stEmpty;  
SetGO goIF\_1\_Format,10;  
WaitGI giIF\_1\_Format,10;  
ENDPROC

PROC routine2()  
ErrWrite\I,“Starting..”,stEmpty;  
SetGO goIF\_2\_Format,20;  
WaitGI giIF\_2\_Format,20;  
ENDPROC

PROC routine3()  
ErrWrite\I,“Starting..”,stEmpty;  
SetGO goIF\_3\_Format,30;  
WaitGI giIF\_3\_Format,30;  
ENDPROC

As you can see these routine are technically the same only dealing with different I/Os. Any chance to make it one routine and just keep calling it with different I/O as parameter or something?

Thanks

---

<div class="post-metadata">

**Author:** ![DenisFR](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@DenisFR](https://tech-community.robotics.abb.com/u/DenisFR)\
**Post date:** [October 2, 2018, 10:10am UTC](https://tech-community.robotics.abb.com/t/generic-code-with-different-i-os/8492/2 "2018-10-02T10:10:11Z")

</div>

Hello,  
you can code your routine like this:

```auto
  PROC routineStd(signalgo goOut, signalgi giIn, num nValue)
    ErrWrite\I,"Starting..",stEmpty;
    SetGO goOut,nValue;
    WaitGI giIn,nValue;
  ENDPROC

```

Then call it by:

```auto
    routineStd goIF_1_Format, giIF_1_Format, 10;
    routineStd goIF_2_Format, giIF_2_Format, 20;
    routineStd goIF_3_Format, giIF_3_Format, 30;

```

---

<div class="post-metadata">

**Author:** ![ko414du4](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@ko414du4](https://tech-community.robotics.abb.com/u/ko414du4)\
**Post date:** [October 2, 2018, 10:34am UTC](https://tech-community.robotics.abb.com/t/generic-code-with-different-i-os/8492/3 "2018-10-02T10:34:12Z")

</div>

Hi Denis,

I tried this and at first it gave me an error “signalgi not value type”. Did some reading and apparently since signalX is a semi-value type, the only way to use them as parameters are if you declare the parameters as VAR. It kinda makes sense really.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Micky](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Micky](https://tech-community.robotics.abb.com/u/Micky)\
**Post date:** [October 2, 2018, 11:06am UTC](https://tech-community.robotics.abb.com/t/generic-code-with-different-i-os/8492/4 "2018-10-02T11:06:05Z")

</div>

Hello,  
you have to use the argument “VAR” if you want to handover signals to a routine

```auto
 PROC routineStd( **VAR** signalgo goOut, **VAR** signalgi giIn, num nValue)

```

It is also possible that you use the instruction ALIASIO to connect a real signal name to a signal declaration in your program.

**Example:**

PROC myRoutine(num Value)  
VAR signalgo goFormat;  
VAR signalgi giFormat;  
VAR string stSignal;

ErrWrite\I,“Starting..”,stEmpty;  
stSignal:=“goIF\_”+ValToStr(Value)+“\_Format”;  
AliasIO stSignal,goFormat;

stSignal:=“giIF\_”+ValToStr(Value)+“\_Format”;  
AliasIO stSignal,giFormat;

SetGO goFormat,20;  
WaitGI giFormat,20;

ENDPROC

/BR  
Micky

---

<div class="post-metadata">

**Author:** ![ko414du4](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@ko414du4](https://tech-community.robotics.abb.com/u/ko414du4)\
**Post date:** [October 2, 2018, 12:36pm UTC](https://tech-community.robotics.abb.com/t/generic-code-with-different-i-os/8492/5 "2018-10-02T12:36:54Z")

</div>

Hi Micky,

Thanks for this. I’ll give it a go and keep the forum updated!

Cheers,

---

<div class="post-metadata">

**Author:** ![ko414du4](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@ko414du4](https://tech-community.robotics.abb.com/u/ko414du4)\
**Post date:** [October 2, 2018, 1:40pm UTC](https://tech-community.robotics.abb.com/t/generic-code-with-different-i-os/8492/6 "2018-10-02T13:40:05Z")

</div>

Hi Micky,

It works like a charm. Thanks for this!
