Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing two binary files? 1

Status
Not open for further replies.

redgenie

Programmer
Aug 10, 2000
36
GB
I'm having trouble comparing 2 binary files, can anyone give me a pointer to what I'm doing wrong in the following function:

Code:
private function filesSame(FileName1, FileName2)

	Const adTypeBinary = 1

	'Create Stream objects
	Dim BinaryStream1, BinaryStream2
	Set BinaryStream1 = CreateObject("ADODB.Stream")
	Set BinaryStream2 = CreateObject("ADODB.Stream")

	'Specify stream type - we want To get binary data.
	BinaryStream1.Type = adTypeBinary
	BinaryStream2.Type = adTypeBinary

	'Open the stream
	BinaryStream1.Open
	BinaryStream2.Open

	'Load the file data from disk To stream object
	BinaryStream1.LoadFromFile FileName1
	BinaryStream2.LoadFromFile FileName2

	'Open the stream And get binary data from the object
	BinaryFile1 = BinaryStream1.Read
	BinaryFile2 = BinaryStream2.Read

	if BinaryFile1 <> BinaryFile2 then
		filesSame = false
	else
		filesSame = true
	end if

end function

Any help would be greatly appreciated!
 
only thing i can see in here is the possibility of larger files might be exceeding the bounds of the variables :

'Open the stream And get binary data from the object
BinaryFile1 = BinaryStream1.Read
BinaryFile2 = BinaryStream2.Read

perhaps pass the values into binaryfile1(0) and binaryfile2(0)

[thumbsup2]DreX
aKa - Robert
 
No that doesn't work unfortunately. The error I get is a Type Mismatch on the following line:

Code:
if BinaryFile1 <> BinaryFile2 then
 
try if strcomp(binaryfile1,binaryfile2,vbbinarycompare)

[thumbsup2]DreX
aKa - Robert
 
I think your right because even though I am not getting the Type Mismatch error it returns false when comparing two files which are exactly the same.

I'll have a look into the links you provided, thanks!
 
Great stuff, thank you very much guys. You've been very kind :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top