-
Hi,
In order to help me with versioning control from a text file that I receive off the web, I was wondering if there was a way to compare the contents of say a text file named categories.txt and categoriesnew.txt.
I thought about just comparing the size of the 2 files and if there was a difference, I would assume that there has been some updates.. But then I realized that the file size may be identical if the same amount of text was put in as was taken out..
Anyway to compare the contents of these 2 files to return False if the same or True if different? I'm using VB6 Pro..
Any help would be appreciated..
Dan
-
Nevermind.. I just found the solution..
use the LIKE function:
sResult = "string1" LIKE "string2"
Returns 0 if False and -1 if True..
Dan
-
<?>
[code]
'something to think about
Option Explicit
Option Compare Text
Private Sub Form_Load()
Dim x As String, y As String
Dim sResult As Boolean
x = "DirtBagDog"
y = "DirtBagDog"
sResult = "x" Like "y"
If sResult = True Then
MsgBox "Like = Same"
Else
MsgBox "Like = Different"
End If
Dim sresult2 As Integer
sresult2 = StrComp(x, y)
If sresult2 = 0 Then
MsgBox "strComp = Same"
Else
MsgBox "strComp = Different"
End If
End Sub
[code]
-
Here's some code I use in one of my oh-so-cool programs :)
You could also use Open File For Binary... it's faster.
Code:
'first check the filesize
If FileLen(OLDFILE) <> FileLen(NEWFILE) Then
'= updated
'do all the things you need and
Exit Sub/Function 'to prevent it to display it's updated twice :)
End If
'Now the filechecking if the size is the same.
Open OLDFILE For Input As #1
Open NEWFILE For Input As #2
Do While Not EOF(1)
Line Input #1, tmp1
Line Input #2, tmp2
If tmp1 <> tmp2 Then '= Updated!
'Do the things you need
Exit Sub/Function
End IF
Loop
'If the code reaches here there's nothing updated!
Get the idea?
whoohee this is my 800th post :)