I have a table with Bill of Material information in four columns; Parent PN, Child PN, Quantity, Units of Measure.
Given a parent part number as an input I am returning the "exploded" or "indented" bill of material. Essentially that means I am returning all the children of the parent, all the children of the children, etc. At most I have seen five generations. The order of operations is to loop through an array to find the first child, write the row data to a worksheet, recursively call the sub again to look for a child of the child, and so on and so forth until no more children are found.
I have this working but am curious to know if it is not optimized for speed. Say I am at the fourth generation (the first was input by the user), the call stack has three of the same procedure running, are there three of the same arrays loaded into memory or one? If I define the array within the called procedure I think it would be in memory for each, but what if I pass the array into the first call and then recursively call the same array with the same argument name? I could be way overthinking this, but I have tried it both ways and do not know how to tell what it is doing by looking a the Locals window.
I am not changing the array so I have defined it as ByVal. I was expecting an error based on what I was reading on Chip's website but his example was probably doing something different. To give you an idea of size, the array is (1 to 23300, 1 to 4) and I have a BOM with over 300 items so it loops through whole array that many times.
I am guessing it might be faster to build an output array rather than writing to the worksheet but I have not taken that step yet. Any insight into passing arrays recursively or how to tell how many arrays are stored in memory would be greatly appreciated.
Thanks,
Doug
Given a parent part number as an input I am returning the "exploded" or "indented" bill of material. Essentially that means I am returning all the children of the parent, all the children of the children, etc. At most I have seen five generations. The order of operations is to loop through an array to find the first child, write the row data to a worksheet, recursively call the sub again to look for a child of the child, and so on and so forth until no more children are found.
I have this working but am curious to know if it is not optimized for speed. Say I am at the fourth generation (the first was input by the user), the call stack has three of the same procedure running, are there three of the same arrays loaded into memory or one? If I define the array within the called procedure I think it would be in memory for each, but what if I pass the array into the first call and then recursively call the same array with the same argument name? I could be way overthinking this, but I have tried it both ways and do not know how to tell what it is doing by looking a the Locals window.
I am not changing the array so I have defined it as ByVal. I was expecting an error based on what I was reading on Chip's website but his example was probably doing something different. To give you an idea of size, the array is (1 to 23300, 1 to 4) and I have a BOM with over 300 items so it loops through whole array that many times.
I am guessing it might be faster to build an output array rather than writing to the worksheet but I have not taken that step yet. Any insight into passing arrays recursively or how to tell how many arrays are stored in memory would be greatly appreciated.
Thanks,
Doug