RobotStudio event

Generic code with different I/Os

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
Tagged:

Best Answer

Answers

  • DenisFR
    DenisFR ✭✭✭
    Hello,
    you can code your routine like this:
    &nbsp; PROC routineStd(signalgo goOut, signalgi giIn, num nValue)<br>&nbsp;&nbsp;&nbsp; ErrWrite\I,"Starting..",stEmpty;<br>&nbsp;&nbsp;&nbsp; SetGO goOut,nValue;<br>&nbsp;&nbsp;&nbsp; WaitGI giIn,nValue;<br>&nbsp; ENDPROC<br>
    Then call it by:
    &nbsp;&nbsp;&nbsp; routineStd goIF_1_Format, giIF_1_Format, 10;<br>&nbsp;&nbsp;&nbsp; routineStd goIF_2_Format, giIF_2_Format, 20;<br>&nbsp;&nbsp;&nbsp; routineStd goIF_3_Format, giIF_3_Format, 30;<br>



  • 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!
  • Hi Micky,

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

    Cheers,
  • Hi Micky,

    It works like a charm. Thanks for this!