Hi,
I am attempting to read a binary file and then write the contents to a new file. However for some reason some extra characters are placed at the top of the destination file apart from that the files are identical.
Here is the code:
Code:
Option Explicit
Private Sub Form_Load()
Call writeBinFile(App.Path & "\copy.zip", readBinFile(App.Path & "\original.zip"))
End Sub
Function writeBinFile(ByVal bfilename As String, data As Variant)
Dim FileNum As Long
FileNum = FreeFile
Open bfilename For Binary Access Write As #FileNum
Put #FileNum, , data
Close #FileNum
End Function
Function readBinFile(ByVal bfilename As String) As Variant
Dim fl As Long
Dim FileNum As Long
Dim binbyte() As Byte
Dim binfilestr As String
On Error GoTo errHandler
FileNum = FreeFile
Open bfilename For Binary Access Read As #FileNum
fl = FileLen(bfilename)
ReDim binbyte(fl)
Get #FileNum, , binbyte
Close #FileNum
readBinFile = binbyte
Exit Function
errHandler:
Exit Function
End Function
I don’t believe the readBinFile function is causing the problem since its documented on Microsoft’s website http://support.microsoft.com/default...b;en-us;193998
*confused* the attached pictures shows the unknown data appended at the beginning of the file.
PS: The solution can not be achieved by simply copying the file.