LENGTH_ARRAY on Structure array
papadouk
Posts: 58
Having the following code:
when i use LENGTH_ARRAY(MyStruct) i get always zero. I was expected to have a value of 1 but...nope.
Now i have to find the active length either by looping through the array or by keeping an index.
Another thing with arrays is that i cannot Increase the maximum length during run-time. In the Help file, somewhere, is written:
"LENGTH_ARRAY returns the effective length of a dimension of an array: the length set implicitly through array initialization or ARRAY MANIPULATION OPERATIONS (+ and –) or explicitly through a call to SET_LENGTH_ARRAY" which made me think that i could do it.
....i have given up trying to make it happen, so i rest my thoughts in the forum...
Kostas
DEFINE_STRUCTURE STRUCTURE TMyStruct { CHAR cStr1[10]; CHAR cStr2[5]; } DEFINE_VARIABLE TMyStruct MyStruct[3]; DEFINE_START MyStruct[1].cStr1 = 'Test1'; MyStruct[1].cStr2 = '^^';
when i use LENGTH_ARRAY(MyStruct) i get always zero. I was expected to have a value of 1 but...nope.
Now i have to find the active length either by looping through the array or by keeping an index.
Another thing with arrays is that i cannot Increase the maximum length during run-time. In the Help file, somewhere, is written:
"LENGTH_ARRAY returns the effective length of a dimension of an array: the length set implicitly through array initialization or ARRAY MANIPULATION OPERATIONS (+ and –) or explicitly through a call to SET_LENGTH_ARRAY" which made me think that i could do it.
....i have given up trying to make it happen, so i rest my thoughts in the forum...
Kostas
0
Comments
In order to use LENGTH_ARRAY, the structure array must have length by using SET_LENGTH_ARRAY. SO... Instead... use MAX_LENGTH_ARRAY. This returns the upper bounds of the array indicating this is the max length the array can be.
On the same front... you must always have a max array length. What you do to expand... is declare the array to the max size you will ever need, and use SET_LENGTH_ARRAY to indicate how much you are using, than you can use LENGTH_ARRAY and virtually expand it by using SET_LENGTH_ARRAY again.
So, in effect, these functions don't deal with the absolute values in the array, but the effective ones.
All the things you described are included in the way i work with arrays. It has been like this since i step my foot in the deep waters of Netlinx. It just hit me one of these days to get the active length of a struct by using LENGTH_ARRAY instead of the pre - mentioned ways...It didn't work, so i'm back in my hole.
About the Dynamic growing of an array (beyond the MAX length of it's declaration) was a 'C' programming artifact that hounded me..