Hi All, |
Re: Recursively count child objects, display results at heading level. Edit: I've sussed it, it had a recursive function call, I remembered there was something quirky about it. I'm repeating the code in case it comes in handy for other users. It's a very quick and easy way of gathering metrics, particularly if you start introducing conditionals for the counts.
int count = 0
Object o
string countObjs(Object obj)
{
for o in all obj do // For each child of obj
{
if (leaf (o))
{
count ++
}
else // Is a parent, so call countObjs
{
countObjs (o)
}
}
return count ""
}
if (!leaf (obj))
{
obj.attrDXLName = countObjs(obj)
}
else
{
obj.attrDXLName = ""
}
|
Re: Recursively count child objects, display results at heading level. rl4engi - Thu May 27 11:52:06 EDT 2010 Edit: I've sussed it, it had a recursive function call, I remembered there was something quirky about it. I'm repeating the code in case it comes in handy for other users. It's a very quick and easy way of gathering metrics, particularly if you start introducing conditionals for the counts.
int count = 0
Object o
string countObjs(Object obj)
{
for o in all obj do // For each child of obj
{
if (leaf (o))
{
count ++
}
else // Is a parent, so call countObjs
{
countObjs (o)
}
}
return count ""
}
if (!leaf (obj))
{
obj.attrDXLName = countObjs(obj)
}
else
{
obj.attrDXLName = ""
}
This doesn't look right at all. Surely each Heading object wants to set its count to zero before iniating another recursive call. Declaring 'o' globally surely will cause it to fail.
int countObjs(Object obj)
{ // Count all leaf objects under this object
// RECURSION Enabled
if (null(obj)) return(0)
if (isDeleted(obj)) return(0)
if (table(obj) or row( obj)) return(0)
if (cell (obj) or leaf(obj)) return(1)
// Must be heading object
int Count = 0
Object o
for o in all obj do // For each child of obj
{
Count = Count + countObjs(o) // ** RECURSION **
}
return (Count)
} // end countObjs()
int Count = countObjs(obj)
if (Count != 0) //-
then obj.attrDXLName = Count ""
else obj.attrDXLName = ""
else obj.attrDXLName = " "
|