FC:FUNCTION是函数或功能,可以有返回值;
FUNCTION FC1000:DINT //////VOID
VAR_INPUT
N:DINT:=L#0;
END_VAR
VAR_TEMP
I:DINT;
SUM:DINT;
END_VAR
BEGIN
SUM:=0;
FOR I:=1 TO N BY 1 DO
SUM:=SUM+I;
END_FOR;
FC1000:=SUM;
END_FUNCTION
//////
FB:FUNCTION BLOCK是过程或功能块,无返回值;
FUNCTION_BLOCK FB1000
VAR_INPUT
N:DINT:=L#0;
END_VAR
VAR_OUTPUT
SUM:DINT:=L#0;
END_VAR
VAR_TEMP
I:DINT;
END_VAR
BEGIN
SUM:=0;
FOR I:=1 TO N BY 1 DO
SUM:=SUM+I;
END_FOR;
END_FUNCTION _BLOCK