- Local time
- Tomorrow, 08:50
- Joined
- Jan 20, 2009
- Messages
- 12,896
I am extracting data from text files. Ultimately the output will be provided to and operated from Excel so I am doing the whole thing in code using ADO connections and recordsets.
I initially did the text line selection using information from hard coded arrays of strings. When I changed to retrieving this information from a database I wrote a function to return an array which plugged straight into my original parsing structure.
Continuing in the same fashion, for the output recordset structure I used a function to return a two dimensional array of field properties which was then used to construct the recordset. The same array holds the parsing information used to define the start position and width of the data for each field.
All works well but I realised I could achieve the same by just using the recordsets rather than arrays and changing the code to step through them.
One thing I do like about the two dimensional array holding the parsing information is the ability to use a single line making explicit reference to a particular array row using the same counter as the destination field index rather than moving the Field Information recordset independently.
Rather than:
I would be interested in any perspectives about advantages using an array or a recordset in this kind of situation.
Clearly the array must be first created using a MoveNext loop so it is double processing where the array is used only once. But what about where the array was then applied to parsing thousands of lines. Could accessing values from an array be faster than repeatedly moving through a recordset?
I initially did the text line selection using information from hard coded arrays of strings. When I changed to retrieving this information from a database I wrote a function to return an array which plugged straight into my original parsing structure.
Continuing in the same fashion, for the output recordset structure I used a function to return a two dimensional array of field properties which was then used to construct the recordset. The same array holds the parsing information used to define the start position and width of the data for each field.
All works well but I realised I could achieve the same by just using the recordsets rather than arrays and changing the code to step through them.
One thing I do like about the two dimensional array holding the parsing information is the ability to use a single line making explicit reference to a particular array row using the same counter as the destination field index rather than moving the Field Information recordset independently.
Code:
For f = 0 To fu ' fu = Ubound of the field information array
FieldName = rsDataOut.Fields(f).Name
rsDataOut.AddNew FieldName, Mid(InputString, FieldArray(f, 3), FieldArray(f, 4))
Next
Code:
For f = 0 To reccount - 1 ' reccount = rsFieldInfo.Recordcount
FieldName = rsDataOut.Fields(f).Name
rsDataOut.AddNew FieldName, Mid(InputString, rsFieldInfo.Fields(3), rsFieldInfo.Fields(4))
rsFieldInfo.MoveNext
Next
I would be interested in any perspectives about advantages using an array or a recordset in this kind of situation.
Clearly the array must be first created using a MoveNext loop so it is double processing where the array is used only once. But what about where the array was then applied to parsing thousands of lines. Could accessing values from an array be faster than repeatedly moving through a recordset?