Fastest way to search - 2D array!
Posted on 2004-03-27
I have a 2D array.
and so on...something like that. So when I get a string argument, I have to return "emp3" or "32" (either one...as specified).
Public Function GetArrayEquivalent(ByVal strString As String) As String
Dim strTmp As String
Dim lngStart As Long
Dim lngEnd As Long
lngEnd = 1000 'Number of array items/rows
strTmp = strString
For lngStart = 1 To lngEnd
If strString = arr(lngStart, 1) Then strTmp = arr(lngStart, 0): Exit For
GetArrayEquivalent = strTmp
That method is okay. But when I use it for searching in bulk, the program becomes very slow. Of course there is the possibility of DoEvents, but still I feel I am not doing it correctly. Am I correct?
So is there any way to search an array speedily?
(If I use Collections also, maybe the same thing happens internally...like the same search takes place comparing every array item till it finds the particular item?.)