I have an array of String but I do not know how many elements in it. If the user put 3 elements in the array then the total of index = 3. How can I scan all the elements array if it is not equal to '' (meaning NULL) and get the total of index in the array?
Thank you in advance
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can not define dynamic size array in codesys. I guess you have an array with static length but you want to now how many elements is not empty.
for example you have ' StringArrayVar : ARRAY [1..100] OF STRING ' . you can find like that how many elements is not empty;
Hello,
I have an array of String but I do not know how many elements in it. If the user put 3 elements in the array then the total of index = 3. How can I scan all the elements array if it is not equal to '' (meaning NULL) and get the total of index in the array?
Thank you in advance
You can not define dynamic size array in codesys. I guess you have an array with static length but you want to now how many elements is not empty.
for example you have ' StringArrayVar : ARRAY [1..100] OF STRING ' . you can find like that how many elements is not empty;
var
StringArrayVar : ARRAY [1..100] OF STRING ;
i: byte ;
TotalIndex : Byte ;
end_var
TotalIndex := 0 ;
FOR i:=1 TO 100 DO
IF StringArrayVar[i] <> '' THEN TotalIndex := TotalIndex + 1 ; END_IF
END_FOR