Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default fast and simple way to match up arrays

What would be a fast and simple way to match up 2-D arrays with a 1-D array?
The main thing is speed, far less important is simplicity.

These 2-D arrays come from ADO Recordsets.
The matching up will happen on the numbers in the 1-D array and the numbers
in the
first column of the 2-D arrays. All these numbers are integer numbers.
The 1-D array holds all the ID numbers and the 2-array a subset of these ID
numbers.
Both arrays are sorted ascending on these ID numbers.
So for example:

array1
1
2
3
4
5
6

array2
2, Apple
3, Pear
4, Orange

resulting array:
1,
2, Apple
3, Pear
4, Orange
5,
6,

Now I have made a Sub that does this and I think it is quite fast (matching
up 2 arrays of
about 25000 rows in about 70 milliseconds) but it is a bit complex.
I have tried a completely different method involving running SQL on text
files. This is very
much simpler, but much slower.
My first attempt was with the Matchup function, but that is even slower.

I am probably not going to improve on my current method, but just wonder if
anybody had any
bright ideas about this problem.
Thanks for any advice.


RBS

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default fast and simple way to match up arrays

Because the ID numbers are unique and sorted this can be done quite simple
like this code fragment:

'arr1 is 1-based
'arr2 is 0-based
'arr3 is 1-based
'SC is a variable starting column in arr3

For r2 = 0 To RC2 - 1
For r1 = r1F To RC1
If arr1(r1) = arr2(r2, 0) Then
For c = 1 To CC2
arr3(r1, SC + c - 1) = arr2(r2, c)
Next
r1F = r1 + 1
Exit For
End If
If arr1(r1) arr2(r2, 0) Then
Exit For
End If
Next
Next

And I don't think this can be done much faster, so forget about this.


RBS


"RB Smissaert" wrote in message
...
What would be a fast and simple way to match up 2-D arrays with a 1-D
array?
The main thing is speed, far less important is simplicity.

These 2-D arrays come from ADO Recordsets.
The matching up will happen on the numbers in the 1-D array and the
numbers in the
first column of the 2-D arrays. All these numbers are integer numbers.
The 1-D array holds all the ID numbers and the 2-array a subset of these
ID numbers.
Both arrays are sorted ascending on these ID numbers.
So for example:

array1
1
2
3
4
5
6

array2
2, Apple
3, Pear
4, Orange

resulting array:
1,
2, Apple
3, Pear
4, Orange
5,
6,

Now I have made a Sub that does this and I think it is quite fast
(matching up 2 arrays of
about 25000 rows in about 70 milliseconds) but it is a bit complex.
I have tried a completely different method involving running SQL on text
files. This is very
much simpler, but much slower.
My first attempt was with the Matchup function, but that is even slower.

I am probably not going to improve on my current method, but just wonder
if anybody had any
bright ideas about this problem.
Thanks for any advice.


RBS


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default fast and simple way to match up arrays

If you're familiar with ADO, there might be a way to write your
information to seperate datatables in a dataset, then use a SQL
statement. I would guess probably pretty easy, and quick to boot.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MATCH Function - 2 Dimension Arrays AZ_Ray Excel Worksheet Functions 3 September 11th 08 10:59 PM
SIMPLE QUESTION need fast answer please Jannie Excel Worksheet Functions 6 October 5th 07 06:22 PM
MATCH being sent two arrays Richard Fangnail Excel Worksheet Functions 2 August 17th 07 02:03 AM
MATCH, INDEX and VLOOKUP with Arrays Dean Hinson[_3_] Excel Programming 2 March 18th 05 03:20 PM
Simple arrays with If statements Andy Excel Programming 4 September 23rd 03 06:15 PM


All times are GMT +1. The time now is 04:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"