length_array & structures
vining
Posts: 4,368
Can one use length_array on a structure. I can't seem to. It would seem somewhat difficult if not impossible inside the structure but what about the upper most level?
sStruct[x].sValue[y].sData[z]
nStructLen = length_array(sStruct) ;
The actual real number of sStruct is 3 and all I get from nStructLen is 0.
If this is impossible what other means is there to make this determination in code other than where this value is defined.
The purpose is to compare structure values written in XML on RAM and reloaded into the structure on start up to compare these values to values that may have been changed or quantities (number of srtuctures) increased.
If quanties and values are the same load the XML and be done but if quantities are different load the XML compare files and if differnet load the new values.
I created a persistent variable to pass to my module to hold this size value from initial start up but was wondering if I could eliminate the var and just use the length_array to determine size changes.
sStruct[x].sValue[y].sData[z]
nStructLen = length_array(sStruct) ;
The actual real number of sStruct is 3 and all I get from nStructLen is 0.
If this is impossible what other means is there to make this determination in code other than where this value is defined.
The purpose is to compare structure values written in XML on RAM and reloaded into the structure on start up to compare these values to values that may have been changed or quantities (number of srtuctures) increased.
If quanties and values are the same load the XML and be done but if quantities are different load the XML compare files and if differnet load the new values.
I created a persistent variable to pass to my module to hold this size value from initial start up but was wondering if I could eliminate the var and just use the length_array to determine size changes.
0
Comments
Not impossible at all ? if I understand the question correctly.
Output when button 1 is pushed first:
Line 1 :: LENGTH_ARRAY(sMyStucts[1].Junk) = 0 - 19:05:35
Output when button 2 is pushed second:
Line 2 :: LENGTH_ARRAY(sMyStucts[1].Junk) = 10 - 19:05:38
Output when button 3 is pushed third:
Line 3 :: LENGTH_ARRAY(sMyStucts[1].Junk) = 6 - 19:05:40
Line 4 :: sMyStucts[1].Junk = Some S - 19:05:40
I'm essentially trying to get the value of "nMaxMyStructs" from LENGTH_ARRAY(sMyStucts) of your example. In other words if we think of the structure as a multi dimensional array the number of tables in sMyStructs not the amount of data in an element of the a table or rows in a table or column in a row, etc.
I just want the numbers of tables. The skeleton or framework of the structure is created at compile time and I'm not looking for data contained in the structure, I'm trying to determine the framework. If that makes any sense! Basically I want to know how many tables of the structure I have to fill or in this particular case how many tables exist so I know how many I should try to compare data from. Comparing possible changes of structure size to that of the structure being loaded from RAM on start up and if there's a difference load the new structure with defaults and forget the old data from file. Possibly populate the existing data into the new structure and load defaults into areas the RAM file can't populate because no previous data existed.
No can do. But like I said that value is set at compile time so you already know it.
I have no idea if I?m answering your question but that?s my story and I?m sticking to it.
Let me try to clarify.
Yes, but I'm trying to compare that known qty of tables to the amount of tables contained in an XML file written to RAM.
Actual my thinking is flawed, cuz if it were possible I would be getting the current number of tables that was just compiled not the amount of tables written to XML unless I parse the XML to make this determination or I would have to do as you suggest and look for data missing in the tables and if for some reason the new compiled structure is smaller than the XML written to RAM when I do my XML_TO_VAR I'll get the error "end of file reached" or something.
I'm just trying to determine if the stored XML file is still valid when a new program is uploaded any time we go through a DEFINE_START routine such as during a reboot or new program upload. Based on that determination I'll either keep the data in the XML or reload defaults or possibly both, load the structure from the XML and if tables were added just load the new tables with defaults.
I understand what I need to do now, I think!
I read the above and it seemed like there were two different thought processes. I'm trying to do what I believe vining was asking and that is to test the length of an array of structures.
The example by Joe seems to test the length of a member of the struct but not the entire struct. In the help file it says:
LONG LENGTH_ARRAY (<type> Array[ ])
<type> may be any intrinsic or user-defined data type.
but I can't get anything to compile using this syntax. I've tried:
cmdCount = LENGTH_ARRAY(<Fireball_MioCmdPairs> MioCmdXRef);
and
cmdCount = LENGTH_ARRAY(Fireball_MioCmdPairs MioCmdXRef);
which don't compile due to a syntax error
and finally
cmdCount = LENGTH_ARRAY( MioCmdXRef) which seems to keep returning zero as described by vining.
I can work around by keeping track of the array, but I have a tendency to use built in functions when they are there.