Hi to all,
I've a little problem with the operator sizeof that is not working with in_out vars. In my case the code is very simple like below:
FUNCTION_BLOCK fb1 VAR_IN_OUT my_array :ARRAY[*] OF STRING; END_VAR VAR_OUTPUT dimension :UINT; END_VAR VAR END_VAR dimension := sizeof(my_array)/sizeof(my_array[0]);
PROGRAM PLC_PRG VAR array1 :ARRAY[0..100] OF STRING; pi :fb1; dim1, dim2 :UINT; END_VAR pi(my_array := array1, dimension=>dim1); dim2 := SIZEOF(array1)/SIZEOF(array1[0]);
In this case the result of dim1 is zero, and the result of dim2 is 101. How can I calculate the right dimension from function block?
thanks Luca
Upper_Bound(my_array,1) - Lower_Bound(my_array,1) + 1
Log in to post a comment.
Hi to all,
I've a little problem with the operator sizeof that is not working with in_out vars. In my case the code is very simple like below:
In this case the result of dim1 is zero, and the result of dim2 is 101. How can I calculate the right dimension from function block?
thanks
Luca
Last edit: lucaver89 2020-04-25
Upper_Bound(my_array,1) - Lower_Bound(my_array,1) + 1