Sorry, you are correct. I was using this to determine the Upper Boundary of an array of type STRUCTURE. In this case the Individual Element length is always returned in Bytes as is the Total length of the Entire Array. So the Math works. I have made a change to the Function to work with the following data types.
BYTE, CHAR, WORD, INT, DWORD, DINT, STRUCTURE.
FUNCTION FC799 : INT
TITLE = 'z999_Size_SCL'
VERSION : '1.0'
KNOW_HOW_PROTECT
AUTHOR : 'UTECH'
VAR_INPUT
SingleDimensionPTR : ANY;
TotalArrayPTR : ANY;
END_VAR
VAR_TEMP
pAny : ANY;
pAnyPtr AT pAny : STRUCT
S7Code : BYTE; // Code for S7 = 0x10
DataType : BYTE; // Code for data type = 0x02 = byte
Length : INT; // Repetition factor = Send/receive length
DBNumber : INT; // Data block Number
MemoryArea : BYTE; // Specified memory area = 0x84 = data block
ByteAddressMSB : BYTE; // Byte address most significant bits
ByteAddressLSB : WORD; // Byte address least significant bits
END_STRUCT;
INDEX : INT; //Used in the FOR NEXT LOOP
ibData: ARRAY[0..15] OF BOOL;
iData AT ibData: INT;
dbData: ARRAY[0..31] OF BOOL;
dData AT dbData: DINT;
IndividualSize : DINT; //Returns the Individual Size of the Single Dimension Array
TotalSize : DINT; //Returns the Total Size of the Entire Array
dType : INT;
END_VAR
BEGIN
iData := 0;
dData := 0;
pAny := SingleDimensionPTR;
iData := pAnyPtr.Length;
dType := BYTE_TO_INT(pAnyPtr.DataType);
FOR INDEX := 0 TO 15 BY 1 DO
dbData[INDEX + 16] := ibData[INDEX];
END_FOR;
IF (dType) = (1) THEN //Bool Data Type - Still need to figure out how to detect length
IndividualSize := dData;
ELSIF (dType) = (2) OR (dType) = (3) THEN //BYTE or CHAR. Individ Length is OK
IndividualSize := dData;
ELSIF (dType) = (4) OR (dType) = (5) THEN //INT or WORD. Individ Length * 2
IndividualSize := dData * 2;
ELSIF (dType) = (6) OR (dType) = (7) THEN //DINT or DWORD. Individ Length * 4
IndividualSize := dData * 4;
ELSE //Structure - Length is in Bytes so everything is ok
IndividualSize := dData;
END_IF;
iData := 0;
dData := 0;
pAny := TotalArrayPTR;
iData := pAnyPtr.Length;
FOR INDEX := 0 TO 15 BY 1 DO
dbData[INDEX + 16] := ibData[INDEX];
END_FOR;
TotalSize := dData;
FC799 := DINT_TO_INT(TotalSize / IndividualSize);
END_FUNCTION