I'm curious as to why you need to create an entirely new set of arrays? You're re-dimming them, populating them, and then immediately inserting the values from the arrays in to the grid. This is very inefficient. There doean't seem to be the requirement for the extra overhead, since you can just as easily copy the data from the recordset to the textgrid directly, without using the extra memory.
Now. Since you're using an unbound grid for display, you can create the extra column in several different places.
I would suggest that you create a placeholder column in your SQL Query. Instead of select *, use a select fieldlist aproach, and add an alias column with a fixed value. The field contents can be updated for any of the records in the recordset..
Select Field1, Field2, ... FieldN, 1 as DupCount from Table...
This will create an additional "field" with an alias of DupCount. Use this field as any other when creating a column in the flexgrid & populating it.
Now, instead of looping through the arrays, loop through the recordset. You can use recordset fields just as easily as you can array elements. (you can refer to the fields by field number, if you wish)
' Open the recordset.
' Populate the grid.
Do While not rs.EOF
k = k + 1 ' Row Counter
grdDistribute.Rows = k + 1
For i = 0 to rs.Fields.Count-1
' Copy all field values for record k to the grid
grdDistribute.TextMatrix(k, i) = rs.Fields(i).Value
Likewise, you can use the recordset values directly when building a SQL insert string.
Now, iterating through a recordset IS less efficient than iterating through an array. However, issuing a redim preserve for every record in the recordset, copying data from recordset to array, and immediately copying data from array to grid is hugely inefficient as well. Not only in processing time, but in wasted memory also. You've already created the overhead of a recordset - why not use IT efficiently instead. (Note that ADO recordset searches and sorts are much more efficient than searches and sorts in arrays, for instance)
Last edited by loquin; 01-31-07 at 01:32.
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert