Re: Compare Text Files
- From: "vbExpert4You@xxxxxxxxx" <vbExpert4You@xxxxxxxxx>
- Date: 20 Apr 2006 03:59:27 -0700
If you're using binary search you want to make sure the arrays are
sorted. It won't work if they're not. I see from your original
example the input wasn't. If it's not sorted and you want to use an
array you'll have to implement a sort routine on the array to search
before using binary search.
If you don't have duplicate entries in the text file to search you can
use a Dictionary object. (If you have a file like the example given by
Jennifer, this won't work since "Mickey Mouse" is in there more than
once.) Let's say you want to search File1 for the entries in File2.
You can read all of the contents of File1 into a Dictionary and then
read all of the entries from File2 and search the Dictionary with a
call to Exists like this:
If Not MyDictionary.Exists(strToFind) Then
MsgBox strToFind & " does not exist in File1", vbOkOnly
End If
A sample script might look like this:
<script>
Dim MyDictionary
Dim File2 (4)
Dim Index
' Populate the dictionary. It uses a key and value pair.
' Since you only have a key you can use it also as the value.
Set MyDictionary = CreateObject("Scripting.Dictionary")
MyDictionary.Add("Baseball", "Baseball")
MyDictionary.Add("Football", "Football")
MyDictionary.Add('Soccer", "Soccer")
MyDictionary.Add("Basketball", "Basketball")
' Populate the second array. In your script you'll probably
' want to read it from the file.
File2(0) = "Baseball"
File2(1) = "Football"
File4(3) = "Basketball"
' Let's go through the array and see if its entries are not
' in the MyDictionary object.
For Index = 0 To UBound(File2)
If Not MyDictionary.Exists(File2(Index)) Then
MsgBox File2(Index) & " does not exist in the first file.",
vbOkOnly
End If
Next
</script>
.
- References:
- Compare Text Files
- From: HeartSA
- Re: Compare Text Files
- From: Jennifer
- Compare Text Files
- Prev by Date: Re: NTbackup issue drives me crazy!
- Next by Date: Need help executing php from vbscript
- Previous by thread: Re: Compare Text Files
- Next by thread: Re: List domain members of local group
- Index(es):
Relevant Pages
|