A dictionary object would probably be more efficient for what you're
trying to do.
Dim Dictionary
Dim MyIndex(0)
Set Dictionary = CreateObject("Scripting.Dictionary")
Dictionary("Fred") = 0
Dictionary("Hilidays with Fred") = 1
Dictionary("Killing Fred") = 2
Dictionary("Fred and Jane go to Town") = 3
If Dictionary.Exists("Fred") Then
MyIndex(0) = "Fred"
End If
MsgBox MyIndex(0)
| What the most efficient way to seacrh for an exact match in an array
in VBS?
| I know I can run a for/next loop up to the Ubound of the array, but I
was
| hoping there was something neater?
|
| I was going to use the filter function....but....according to the
| documentation and examples this does substring matches, which I DONT
want. I
| only want a match if the entire array item exactly matches the
comparison
| stirng.
|
| This a M$s example:
| Dim MyIndex
| Dim MyArray (3)
| MyArray(0) = "Sunday"
| MyArray(1) = "Monday"
| MyArray(2) = "Tuesday"
| MyIndex = Filter(MyArray, "Mon") ' MyIndex(0) contains "Monday".
| This would be useless to me. I am looking for book titles, where it is
quite
| possible for many titles to contain the same substring.
| eg
| Dim MyIndex
| Dim MyArray (4)
| MyArray(0) = "Fred"
| MyArray(1) = "Hilidays with Fred"
| MyArray(2) = "Killing Fred"MyArray(3) = "Fred and Jane go to Town"
| MyIndex = Filter(MyArray, "Fred") => I only want to contain
MyArray(0)Is
| this possble of must I resort to stepping through the array?Al Blake,
| Australia
|
|
|
|
|