当一回孔乙己,如题。
//copy a array totally to another array
//first way: use SFC20
#Error := BLKMOV(SRCBLK := #SourceArray, DSTBLK =>#DestinationArray_1);
//second way: copy the elements one by one
FOR #index := 0 TO 9 DO
#DestinationArray_2[#index] := #SourceArray[#index];
END_FOR;
#index := #index + 1;
//third way: use the name of array
#DestinationArray_3 := #SourceArray;
//Error check
FOR #index := 0 TO 9 DO
IF (#DestinationArray_1[#index] <> #SourceArray[#index]) THEN
#Error_1 := TRUE;
ELSE
IF (#DestinationArray_2[#index] <> #SourceArray[#index]) THEN
#Error_2 := TRUE;
ELSE
IF (#DestinationArray_3[#index] <> #SourceArray[#index]) THEN
#Error_3 := TRUE;
ELSE
;
END_IF;
END_IF;
END_IF;
END_FOR;
若要倒序复制,则变更索引下标即可:
//second way: copy the elements one by one
FOR #index := 0 TO 9 DO
#DestinationArray_2[9-#index] := #SourceArray[#index];
END_FOR;
#index := #index + 1;
或者
//second way: copy the elements one by one
FOR #index := 0 TO 9 DO
#DestinationArray_2[#index] := #SourceArray[9-#index];
END_FOR;
#index := #index + 1;