Help Reading Bytes for File Compare
Hullo,
I was wondering if anybody out there could help me with some basic syntax and methods of extracting bytes from a file (eg text file) for comparison with the bytes from a another file, for a file compare I've been asked to do.
Put simply, it has to output something like this:
Comparing files file1.txt and file2.txt
0000000A: 31 33
0000000C: 33 31
0000000F: 34 36
00000011: 36 34
00000014: 37 39
00000016: 39 37
00000023: 4D 6D
00000024: 4E 6E
00000025: 4F 6F
How do I read the bytes from file1 so I can compare them with file2... I've done it for ascii compare, but basically I don't know how to read each byte suitably. There's a command I'm sure, anyone know what it is and how to use it? Pretty simple for anyone that's done it I know, but I can't find help notes anywhere for some strange reason.
Email me at [email protected] if you can help
Cheers
:D
Re: Help Reading Bytes for File Compare
you will just have to read the file into a string variable and compare byte by byte.
refer http://vblib.virtualave.net, ReadFileStr in vbFileIO read a file into string variable.
the using Mid, you can extra each byte from the string using a for loop
HTH
Re: Help Reading Bytes for File Compare
ha **** that will work ... I was trying to use Get() all day! :) Thanks for the quick response too...
I'll let ya know how it all turns out :D
cheers
Dom
:D
Re: Help Reading Bytes for File Compare
You can do it using the Get Statement. Here is an example code
'This function gives you the file both as a byte array and a string
'Using the byte array to process the bytes individually is faster than using mid$
'to extract each character from a string.
'
private Function OpenAFile(Filename as string) as Long
Dim FileAsByte() as Byte
Dim FileAsStr as string
Dim FileHandle as Long
FileHandle = FreeFile
Open Filename for binary as FileHandle
ReDim FileAsByte(LOF(FileHandle))
get FileHandle, , FileAsByte
FileAsStr = StrConv(FileAsByte(), vbUnicode)
' Do your stuff here
Close FileHandle
TransmitAFile = len(FileAsStr)
FileAsStr = ""
Erase FileAsByte
End Function