Re: Compare Text Files

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



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>

.



Relevant Pages

  • Re: optimizing text file searches
    ... I just wrote a quick script to meet my needs, ... it takes about 25 minutes for 5000 entries. ... create an array of matches but only print the first entry found. ...
    (comp.lang.perl.misc)
  • Re: Setting up a variable array based on form input
    ... What I need to build is an Internal Rate of Return (IRR) into this ... Static ValuesAs Double 'Array of values ... automatically based on the loan term selected on the form. ... Static Entries As Integer ...
    (comp.databases.ms-access)
  • Re: Client-side search engine capable of indexing .pdf files is needed.
    ... simple array) I suppose that most of the job is made. ... The index lookup needs to be fast, ... only 1500 entries, which isn't even close to what we're dealing here. ... encoding doesn't match the search encoding. ...
    (comp.lang.javascript)
  • Re: Non-Scrolling Background inside CScrollView
    ... Now i will create an array containing the complete output (all buttons, ... entries and entry separators). ... When scrolling i just display the "visible" entries from the array in ... the distance from top to the corrosponding entry. ...
    (microsoft.public.vc.mfc)
  • Re: Array and resize
    ... For obvious reasons, we want the created table to have a header, ... option instead of placing the array directly into a 4x8 range. ... I wanted to use/test the resize option, since the entries from the FE ...
    (microsoft.public.excel.programming)