# Looking for a way to simplify the main module for my robot

**URL:** <https://tech-community.robotics.abb.com/t/looking-for-a-way-to-simplify-the-main-module-for-my-robot/11806>\
**Category:** RAPID Programming\
**Tags:** irc5, robotstudio, rapid\
**Created:** [February 27, 2025, 7:52am UTC](https://tech-community.robotics.abb.com/t/looking-for-a-way-to-simplify-the-main-module-for-my-robot/11806 "2025-02-27T07:52:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![HaydenW29](https://avatars.discourse-cdn.com/v4/letter/h/7ea924/32.png) [@HaydenW29](https://tech-community.robotics.abb.com/u/HaydenW29)\
**Post date:** [February 27, 2025, 7:52am UTC](https://tech-community.robotics.abb.com/t/looking-for-a-way-to-simplify-the-main-module-for-my-robot/11806/1 "2025-02-27T07:52:15Z")

</div>

Hello,

I’m looking for a way to simplify my main module as right now it is very lengthy. For reference, I have over 100 different part programs, and for each new part, I’m having to add a new section to the main module as well as put the routine in our PC.

Here is how we are currently calling part routines:

IF Part\_Number=3 THEN

StartLoad \Dynamic, “pc:” \File:=“m\_2YD\_SLANT\_FR\_SHT.mod”,load3;  
WaitLoad load3;  
%“r\_2YD\_SLANT\_FR\_SHT”%;  
Save “m\_2YD\_SLANT\_FR\_SHT” \Filepath:=“pc:m\_2YD\_SLANT\_FR\_SHT.mod”;  
UnLoad “pc:/m\_2YD\_SLANT\_FR\_SHT.mod”;  
GOTO Program\_Start;  
ENDIF

It would be important to note that we have an FTP server setup and we are loading modules/routines from a PC and dumping them after the run.

Also I would like to know if there are any advantages to using TEST/CASE/ENDTEST vs doing an IF/ENDIF.

I know this is a lot, but thanks. Let me know if I need to give any more information.

---

<div class="post-metadata">

**Author:** ![Tompanhuhu](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/tompanhuhu/32/3366_2.png) [@Tompanhuhu](https://tech-community.robotics.abb.com/u/Tompanhuhu)\
**Post date:** [February 27, 2025, 3:05pm UTC](https://tech-community.robotics.abb.com/t/looking-for-a-way-to-simplify-the-main-module-for-my-robot/11806/2 "2025-02-27T15:05:22Z")

</div>

Create an array with the program name at each index that corresponds to the program number.  
You can make the array longer with more programs.

```auto
MODULE NewModule
    
    PERS string ProgramList{4}:=[
    "2YD_SLANT_FR_SHT",
        "2YD_SLANT_FR_SHT_2",
        "2YD_SLANT_FR_SHT_3",
        "2YD_SLANT_FR_SHT_4"
    ];
    
    FUNC string fGetModuleName()
        RETURN "m_"+ProgramList{Part_Number};
    ENDFUNC
    
    FUNC string fGetModuleNameWithExtension()
        RETURN "m_"+ProgramList{Part_Number}+".mod";
    ENDFUNC
    
    FUNC string fGetRoutineName()
        RETURN "r_"+ProgramList{Part_Number};
    ENDFUNC
    
    PROC main()
        !Add your code here
        StartLoad \Dynamic, "pc:" \File:=fGetModuleNameWithExtension(),load3;
        WaitLoad load3;
        %fGetRoutineName()%;
        Save fGetModuleName() \Filepath:="pc:"+fGetModuleNameWithExtension();
        UnLoad "pc:/"+fGetModuleNameWithExtension();
        GOTO Program_Start;
    ENDPROC
    
ENDMODULE

```

This is just an example, there are many ways of doing this.

---

<div class="post-metadata">

**Author:** ![HaydenW29](https://avatars.discourse-cdn.com/v4/letter/h/7ea924/32.png) [@HaydenW29](https://tech-community.robotics.abb.com/u/HaydenW29)\
**Post date:** [February 27, 2025, 4:35pm UTC](https://tech-community.robotics.abb.com/t/looking-for-a-way-to-simplify-the-main-module-for-my-robot/11806/3 "2025-02-27T16:35:57Z")

</div>

Looks good, thanks! I’ve also seen that there is an instruction that is just Load instead of Load/WaitLoad. Is there any difference? Also would I need to declare each load (load1, load2, load3, etc.)? That’s the way it was setup, so as of now, there are 100+ loads declared at the top of the main module.

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [February 27, 2025, 4:50pm UTC](https://tech-community.robotics.abb.com/t/looking-for-a-way-to-simplify-the-main-module-for-my-robot/11806/4 "2025-02-27T16:50:14Z")

</div>

Here is a snippet of how we handled loading and unloading different program modules:

```auto
CONST listitem partProgram{14}:=[[stEmpty,"FSNA0044 - PCS 1.5 baskets"],[stEmpty,"FSNA0048 - 33K baskets"],
        [stEmpty,"FSNA0051 - GE 7FA Liner"],[stEmpty,"FSNA0114 - GE 7FA Flex Liner"],[stEmpty,"FSNA0061 - GE 9FA Liner"],
        [stEmpty,"FSNA0106 - PCS 2.1 baskets"],[stEmpty,"FSNA0086 - VLM 1.1 baskets"],[stEmpty,"FSNA0012 - 25K baskets"],
        [stEmpty,"FSNA0117 - PCS 1.5 H282 baskets"],[stEmpty,"AT0015 - 33K basket assy respray"],
        ["","AT0016 - 2.1 basket assy respray"],["","AT0018 - Siemens prototype"],["","AT0045 - liner samples"],[stEmpty,"Stop"]];
        PERS string currentfile;

```

```auto
! get part program from operator
        itemSelected:=UIListView(\Result:=buttonAnswer,\Header:="Part Selected",partProgram,\Buttons:=btnOKCancel,\Icon:=iconInfo,\DefaultIndex:=1);

        IF buttonAnswer=resOK THEN
            IF itemSelected=1 THEN
              UnLoad diskhome\File:=currentfile;
              Load diskhome\File:="FSNA0044.MOD";
              currentfile:="FSNA0044.MOD";
              %"FSNA0044:main"%;
            ELSEIF itemSelected=2 THEN
              UnLoad diskhome\File:=currentfile;
              Load diskhome\File:="FSNA0048.MOD";
              currentfile:="FSNA0048.MOD";
              %"FSNA0048:main"%;
            ELSEIF itemSelected=3 THEN
              UnLoad diskhome\File:=currentfile;
              Load diskhome\File:="FSNA0051.MOD";
              currentfile:="FSNA0051.MOD";
              %"FSNA0051:main"%;
            ELSEIF itemSelected=4 THEN
              UnLoad diskhome\File:=currentfile;
              Load diskhome\File:="FSNA0114.MOD";
              currentfile:="FSNA0114.MOD";
              %"FSNA0114:main"%;
			      ELSEIF itemSelected=5 THEN
              UnLoad diskhome\File:=currentfile;
              Load diskhome\File:="FSNA0061.MOD";
              currentfile:="FSNA0061.MOD";
              %"FSNA0061:main"%;
            ELSEIF itemSelected=6 THEN
              UnLoad diskhome\File:=currentfile;
              Load diskhome\File:="FSNA0106.MOD";
              currentfile:="FSNA0106.MOD";
              %"FSNA0106:main"%;
            ELSEIF itemSelected=7 THEN
              UnLoad diskhome\File:=currentfile;
              Load diskhome\File:="FSNA0086.MOD";
              currentfile:="FSNA0086.MOD";
              %"FSNA0086:main"%;
            ELSEIF itemSelected=8 THEN
              UnLoad diskhome\File:=currentfile;
              Load diskhome\File:="FSNA0012.MOD";
              currentfile:="FSNA0012.MOD";
              %"FSNA0012:main"%;
            ELSEIF itemSelected=9 THEN
              UnLoad diskhome\File:=currentfile;
              Load diskhome\File:="FSNA0117.MOD";
              currentfile:="FSNA0117.MOD";
              %"FSNA0117:main"%;
            ELSEIF itemSelected=10 THEN
              UnLoad diskhome\File:=currentfile;
              Load diskhome\File:="AT0015.MOD";
              currentfile:="AT0015.MOD";
              %"AT0015:main"%;
            ELSEIF itemSelected=11 THEN
              UnLoad diskhome\File:=currentfile;
              Load diskhome\File:="AT0016.MOD";
              currentfile:="AT0016.MOD";
              %"AT0016:main"%;
            ELSEIF itemSelected=12 THEN
              UnLoad diskhome\File:=currentfile;
              Load diskhome\File:="AT0018.MOD";
              currentfile:="AT0018.MOD";
              %"AT0018:main"%;
            ELSEIF itemSelected=13 THEN
              UnLoad diskhome\File:=currentfile;
              Load diskhome\File:="AT0045.MOD";
              currentfile:="AT0045.MOD";
              %"AT0045:main"%;
            ELSEIF itemSelected=14 THEN
                GOTO StopCycle;
            ELSE
                GOTO StopCycle;
            ENDIF
        ELSE
            ! if user selects cancel then stop cycle
            GOTO StopCycle;
        ENDIF

```

---

<div class="post-metadata">

**Author:** ![mandolas](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/mandolas/32/2496_2.png) [@mandolas](https://tech-community.robotics.abb.com/u/mandolas)\
**Post date:** [February 27, 2025, 4:53pm UTC](https://tech-community.robotics.abb.com/t/looking-for-a-way-to-simplify-the-main-module-for-my-robot/11806/5 "2025-02-27T16:53:39Z")

</div>

HI …  
The vector solution is very good … my suggestion for Load is that the load instruction is already saved in the program, so when the program loads it already loads the load.  
If this is not possible, I suggest creating a RECORD vector, so you can pass an object that, in addition to the name of the program to be loaded, also contains the LOAD information.

Good job.
