hi all,
Shg (& others) have previously mentioned that functions never need to be recursive, but in this case (nb: it's a sub rather than a function), recursion seems appropriate to me... even if I can't quite make it work
I'm sorry I'm not very succinct in my below description, but I hope that the expected output string examples in column L (+ my attempted coding) will help clarify my aim.
---------------------
My aim is to provide a list of strings at the right hand side of the "Consolidated Query Info" sheet which states all the "Disk Files" which are used as "Data Source Files" (& recursively onwards...) for each row of data where:
- column H only contains a "dot".
- column C shows how many rows relate to the "query" listed in column E.
- column G should match column E (by convention) but that's not always the case.
If column H = "." then check what the Data Source file(s) in column F are, for each row relating to a specific Disk File in column G (they are consecutive for the number of rows listed in column C), and in turn what are the source files for each "Data Source file" by matching the Column F string with a number of consecutive rows with the same string in column G. Once the next set of Disk Files is identified in Column G, look at the "data source files" for these rows & on & on, until the string listed as a data source file, can no longer be found as a Disk File (show this as a " ( - )").
- Creating an output string (see column L) where each opening bracket ("(") can be interpreted as "...relies on..." & each closing bracket (")") represents the closing of the specific level of recursion.
- Note: the first phrase in the strings are currently the Query name from column E rather than column G.
--------------
I run the code via the MacroCaller sub which is near the top of the d__IdentifyingQryChains_ForWeb module. This macro calls BuildQC_ThisQryReliesOnTheseDSF which calls GetDataSourceFileNames which recursively calls itself. GetDataSourceFileNames currently errors out when processing row 119 (or the subsequent processing of row 396) of the spreadsheet & I've added a msgbox to Stop the code.
Current Output keeps looping until the macro is stopped whereas it should move on by itself!
"IQUSRLIB.SUPPLIER ( IQUSRLIB.FROZ_INV3 ( IQUSRLIB.FROZ_INV2 ( IQUSRLIB.FROZ_INV1 ( IQUSRLIB.FROZ_INV ( OSLTHLF3.INP60 ( - ) OSLTHLF3.INP35 ( - ) ) OSLTHLF3.INP35 ( - ) OSLTHLF3.INP15 ( - ) ) OSLTHLF3.INP80 ( - ) OSLTHLF3.INP84 ( - ) IQUSRLIB.FROZ_INV1 ( IQUSRLIB.FROZ_INV ( OSLTHLF3.INP60 ( - ) OSLTHLF3.INP35 ( - ) ) OSLTHLF3.INP35 ( - ) OSLTHLF3.INP15 ( - ) ) OSLTHLF3.INP80 ( - ) OSLTHLF3.INP84 ( - ) IQUSRLIB.FROZ_INV1 ( IQUSRLIB.FROZ_INV ( OSLTHLF3.INP60 ( - ) OSLTHLF3.INP35 ( - ) )..."
To help identify what is going wrong I have included code to create a Log file of various code sections throughout the macro (+ present the strings in the first blank column). The created log file is saved in the same folder as the workbook containing the code.
QUESTION:
I think that I have over-complicated the recursion & I'm going to have a go at simplifying & re-writing my code at work tomorrow. However, if anyone can identify what I've done wrong in the existing code, can you please let me know?
(eg byRef v byVal etc)
Any comments/code fixes would be very much appreciated.
Thanks in advance,
Rob
Bookmarks