Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Populate Array using the FOR instruction

dsanow92
2021-04-13
2021-04-14
  • dsanow92 - 2021-04-13

    I am trying to populate a large number of variables that looks like this.

    GVL.HMITags.MasterPortStatus[1]:= MasterStatusPort1;
    GVL.HMITags.MasterPortStatus[2]:= MasterStatusPort2;
    GVL.HMITags.MasterPortStatus[3]:= MasterStatusPort3;
    GVL.HMITags.MasterPortStatus[4]:= MasterStatusPort4;
    GVL.HMITags.MasterPortStatus[5]:= MasterStatusPort5;
    GVL.HMITags.MasterPortStatus[6]:= MasterStatusPort6;
    GVL.HMITags.MasterPortStatus[7]:= MasterStatusPort7;
    GVL.HMITags.MasterPortStatus[8]:= MasterStatusPort8;

    I'm looking to simplyfy my code by using the FOR loop but how do I change the MasterStatusPortX
    It should look something like what I have below but how do I attach that last tag using the "i" variable also

    FOR i := 1 TO 8 DO
    GVL.HMITags.MasterPortStatus[i]:= MasterStatusPort??
    END FOR

     
  • dumpfbacke - 2021-04-14

    in my opinion you have to make array of "MasterStatusPort" too.

    FOR i := 1 TO 8 DO
    GVL.HMITags.MasterPortStatus[i]:= MasterStatusPort[i]
    END FOR

     

Log in to post a comment.