Re: fastest way to sort 2-D variant arrays?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



You can use the same code, just change the field names that are added to
suit your needs, and then change the FSO loop section to loop through the
array, and add the elements to the recordset using the AddNew statement.

Lance

"RB Smissaert" <bartsmissaert@xxxxxxxxxxxxxxxx> wrote in message
news:uuVoKFzbGHA.2404@xxxxxxxxxxxxxxxxxxxxxxx
Thanks for the tip.
I was doing something very different, running SQL on text files and then
writing
the text back to the array.
Will give this a go.
How would I write my variant array to the recordset?

RBS

"Lance Wynn" <LanceWynn@xxxxxxxxxxxxxxxx> wrote in message
news:uiFNHrxbGHA.3632@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
Rather then using a text file or mdb -as you will have some extra overhead
writing to the file, and then again reading from the file. Just do it in
memory by creating an ADO Recordset, adding the fields, and then inserting
the values.

Here is something that I use on an ASP page to sort files by date there
are
up to 20,000 to 30,000 files in the directory depending on the day, and I
have found it to be pretty fast. (the sort seems to be faster then
looping
through the files using the FSO object.)

dim rs
set rs=createObject("adodb.recordset")

rs.Fields.Append "ID", 3
rs.Fields.Append "Name", 200, 100
rs.Fields.Append "LastModified", 133

rs.Open

for each file in folder.files
rs.AddNew
rs.Fields("Name").Value = file.Name
rs.Fields("LastModified").Value = file.DateLastModified
next
rs.Update

rs.Sort = "LastModified Desc"
do until rs.EOF
' do stuff with the RS
loop


Lance

"RB Smissaert" <bartsmissaert@xxxxxxxxxxxxxxxx> wrote in message
news:ulAyfJubGHA.864@xxxxxxxxxxxxxxxxxxxxxxx
Yes, I tried that. Didn't find it was faster, but I do use it as it easy
to
do a multi-column sort.
With the ADO sort I use text files to keep the data and maybe it can be
made
faster if I used a .mdb file.
Did some testing though and I don't think it made much difference.

RBS

"Lance Wynn" <LanceWynn@xxxxxxxxxxxxxxxx> wrote in message
news:ucDW8DubGHA.4900@xxxxxxxxxxxxxxxxxxxxxxx
Have you tried ADO to do the sorting? It may not be the fastest, but it
i
very flexible. I've done sorts on several hundred thousand records that
take less then a second.



"RB Smissaert" <bartsmissaert@xxxxxxxxxxxxxxxx> wrote in message
news:eQlgK%23tbGHA.1208@xxxxxxxxxxxxxxxxxxxxxxx
What would be the fastest way to sort large (up to a few million rows)
2-D
variant arrays?
I am working in Excel VBA, but never found a good answer on this in the
Excel programming group.
My particular arrays nearly always have long numbers in the first column
and
that is nearly always the column
these arrays need sorting on. The other columns have different data
types.
Integer and non-integer numbers, strings
and boolean values.
I do this now with a standard quicksort in an ActiveX dll, but thought
there
might be better (faster) ways to do this.
There is a free .xll add-in, written by Laurent Longre that does it
faster,
but there is a drawback in that it can alter the
base of the array, so then I will have to run a double loop to go back to
the old base type.
I thought a C++ dll might be the answer, but it doesn't seem to be the
case.
Thanks for any advice.

RBS






.



Relevant Pages

  • RE: Error 3021
    ... The only thing I see is that after you open the recordset, ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ...
    (microsoft.public.access.modulesdaovba)
  • Re: Sorting VBScript Array
    ... I would like to have the option to sort ... Michael Harris containing the word recordset. ... 'This sample code sets up a 3 by 5 array, adds data to it, ... Dim sMsg ...
    (microsoft.public.scripting.vbscript)
  • Re: fastest way to sort 2-D variant arrays?
    ... and then change the FSO loop section to loop through the ... array, and add the elements to the recordset using the AddNew statement. ... How would I write my variant array to the recordset? ... Here is something that I use on an ASP page to sort files by date there ...
    (microsoft.public.vb.general.discussion)
  • Re: fastest way to sort 2-D variant arrays?
    ... The actual sort of the recordset is very fast, but what makes it slow is ... I take there is no other way to this than in a loop with: ... array, and add the elements to the recordset using the AddNew statement. ...
    (microsoft.public.vb.general.discussion)
  • Re: confused with sort and foreach ($EmailList as $key => $value) {..}
    ... I am trying to sort a multi-dimensional array and the loop through the ...
    (comp.lang.php)