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

filling a structure with values

shooter
2015-04-16
2015-04-20
  • shooter - 2015-04-16

    I want to fill a structure (agenda) with values. When doing in a program and filling them works great

    FUNCTION_BLOCK Schedule
    VAR_INPUT
       Year:INT;
       ariSchedule: ARRAY [0..10] OF Agenda:=(name:='name' );
    so i can fill name active day and mode.
    How to fill sdtStart with values, as i get erronous values when using sdtstart.Year
    so (name:='name',sdtstart.year:=2015) is not working, how to solve this?
    (*TYPE Agenda :
    STRUCT
       Name:STRING(30);
       sdtStart:SDT;
       sdtEnd:SDT;
       Activeday: ARRAY[1..7] OF BOOL;
       Mode:INT;
    END_STRUCT
    END_TYPE
    *)
    TYPE SDT :
    STRUCT
       YEAR : INT;
       MONTH : INT;
       DAY : INT;
       WEEKDAY : INT;
       HOUR : INT;
       MINUTE : INT;
       SECOND : INT;
       MS : INT;
    END_STRUCT
    END_TYPE
    (* revision history
    hm   18. oct. 2008
       original version
    *)
    END_VAR
    

    I did find a work around by filling them in initialisation (i want to fill them in my library)

     
  • Anonymous - 2015-04-20

    Originally created by: scott_cunningham

    From the CoDeSys help on array initialization:

    I got this declaration line to work:

    VAR
       ariSchedule: ARRAY[0..10] OF T_AGENDA:= [(Name:='1st meeting', sdtStart:=(YEAR:=2016, MONTH:=1, DAY:= 1)),
                                                (Name:='2nd meeting', sdtStart:=(YEAR:=2016, MONTH:=12, DAY:= 31))];
    END_VAR
    

    Hope this helps.

     
  • shooter - 2015-04-20

    Yes now it is working i had to remove the [] btw.
    thanks, i have been fiddling on it for 4 hours always changing the (.,;*&^%$[
    and i knew the answer was short by.

     

Log in to post a comment.