





数组间连续单元块的复制操作,完全可以通过调用系统功能块SFC20实现,简洁高效,使用时仅须注意格式正确二者长度一致即可。
此帖没有使用上述方法,而是采用了一种比较”糟糕“的方法,纯属个人无聊的产物,对细节有兴趣的朋友可以看看,参考一下;没兴趣的朋友,笑笑就好。
//initialize the #ErrorMessage and #ErrorWord
#ErrorMessage := '';
#ErrorWord := 0;
//deal with input ANY by using the function "AT" in temp
#tempInputANY := #SourceArray;
//get #srcTotalElements
#srcTotalElements := #TempSource.Repetition_factor;
//get the srcMaxIndex and srcMinIndex
#srcMaxIndex := #srcTotalElements - 1;
#srcMinIndex := 0;
//deal with output ANY by using the function "AT" in temp
#tempOutputANY := #DestinationArray;
//get #dstTotalElements
#dstTotalElements := #TempDestination.Repetition_factor;
//get the desMaxIndex and desMinIndex
#dstMaxIndex := #dstTotalElements - 1;
#dstMinIndex := 0;
//conditions judge: the set value of the "stopIndex" in the range of allowed.
#stopIndexInRange := (#srcStopIndex < #srcTotalElements) AND (#dstStopIndex < #dstTotalElements);
//judge source's index
IF (#srcStopIndex >= #srcTotalElements) = TRUE THEN
#ErrorWord := w#16#1;
#ErrorMessage := #srcStopIndexOutRange;
END_IF;
//judge destination's index
IF (#dstStopIndex >= #dstTotalElements) = TRUE THEN
#ErrorWord := w#16#2;
#ErrorMessage := #dstStopIndexOutRange;
END_IF;
//judge length of copied data zone
#srcCopyDatasLength := #srcStopIndex - #srcStartIndex;
#dstCopyDatasLength := #dstStopIndex - #dstStartIndex;
#lengthEqual := (#srcCopyDatasLength = #dstCopyDatasLength);
IF (#srcCopyDatasLength > #dstCopyDatasLength) = TRUE THEN
#ErrorWord := w#16#3;
#ErrorMessage := #"SrcZone_>_dstZone";
END_IF;
IF (#srcCopyDatasLength < #dstCopyDatasLength) = TRUE THEN
#ErrorWord := w#16#4;
#ErrorMessage := #"SrcZone_<_dstZone";
END_IF;
//judge data type matched or not
#dataTypeMatch := (#TempSource.DataType = #TempDestination.DataType);
//allow copy operation
#copyAllow := #stopIndexInRange AND #lengthEqual AND #dataTypeMatch;
//copy operation
IF #copyAllow = TRUE THEN
#dstIndex := #dstStartIndex;
FOR #srcIndex := #srcStartIndex TO #srcStopIndex DO
#DestinationArray[#dstIndex] := #SourceArray[#srcIndex];
#dstIndex := #dstIndex + 1;
END_FOR;
END_IF;