9/6/2022 5:55 PM | |
Joined: 12/20/2018 Last visit: 1/20/2024 Posts: 63 Rating: (0) |
Hello friends, I am sorting the data in a data block from smallest to largest, my code is working. However, I'm having a problem, I don't want the value "0" to be processed. So I want DB101.DBD 0 to be greater than Zero, if any value in DB101 Array is greater than zero, it will sort with zero at the end and write the smallest value to DB101.DBD0, but if all values in DB101 are "0", only that time DB101.DBD0 value can be equal to zero. What changes do I need to make in the code for this? Could you help. FUNCTION_BLOCK FB100 VAR_IN_OUT Start:INT; // DB101 Start Index End :INT; // DB101 End Index END_VAR VAR i,j:INT; Swap:REAL; // END_VAR BEGIN FOR i:=Start TO (End-1) BY 1 DO FOR j:= i+1 TO End BY 1 DO IF DB101.Data[i]> DB101.Data[j] THEN Swap :=DB101.Data[j]; DB101.Data[j]:=DB101.Data[i]; DB101.Data[i]:=Swap; END_IF; END_FOR; END_FOR; END_FUNCTION_BLOCK DATA_BLOCK DB101 //DB 101 STRUCT Data : ARRAY [0..4] OF REAL; END_STRUCT BEGIN END_DATA_BLOCK
AttachmentSort Numbers_083948.txt (667 Downloads) |
Follow us on