-
Oct 21st, 2007, 08:45 PM
#1
Thread Starter
Lively Member
[VB6] Text Differences
Say I have 2 files, and they are both different. One has more stuff than others.
Example:
File1: "Hello"
File2: "Hello1 Hello"
How could I compare the 2 files, find the differences in text, and add the differences to the first file?
-
Oct 21st, 2007, 09:33 PM
#2
Frenzied Member
Re: [VB6] Text Differences
Testing if two strings are not the same is easy.
Finding what the differences are is trickier.
In your example, would File2 be File1 & "1 Hello" or would it be "Hello1 "& File1?
What do you want to do?
What are these files?
What kind of data do they contain and how ae they formatted?
-
Oct 22nd, 2007, 05:55 AM
#3
Re: [VB6] Text Differences
Try this
Code:
Private Function CompareFiles(FirstFile As String, SecondFile As String) As Boolean
'Description: Compares the content of two files
Dim Part As Long
Dim Whole As Long
Dim Part As Long
Dim Start As Long
Dim Buffer1 As String
Dim Buffer2 As String
Dim x As Long
Open FirstFile For Binary As #1
Open SecondFile For Binary As #2
CompareFiles = True
If LOF(1) <> LOF(2) Then
CompareFiles = False
Else
Whole = LOF(1) \ 10000 'number of whole 10,000 byte chunks
Part = LOF(1) Mod 10000 'remaining bytes at end of file
Buffer1 = String$(10000, 0)
Buffer2 = String$(10000, 0)
Start = 1
For x = 1 To Whole 'this for-next loop will get 10,000
Get #1, Start, Buffer1 'byte chunks at a time.
Get #2, Start, Buffer2
If Buffer1 <> Buffer2 Then
CompareFiles = False
Exit For
End If
Start = Start + 10000
Next
Buffer1 = String$(Part, 0)
Buffer2 = String$(Part, 0)
Get #1, Start, Buffer1 'get the remaining bytes at the end
Get #2, Start, Buffer2 'get the remaining bytes at the end
If Buffer1 <> Buffer2 Then CompareFiles = False
End If
Close #1
Close #2
If CompareFiles Then
MsgBox "Files are identical"
Else
MsgBox "Files are NOT identical"
End If
End Function
I don't remember where I got it, but I've used it a couple of times and it seems to work fine.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|