I want to write a program which merge two binary files with eachother, I could write it to some extent but it works only for small size files (smaller than 1GB) but I need it for big files from 1GB ~ 10GB. My main problem is about the array dimention which is limited to PC RAM. I ended up using For ... next to overcome the array demintion limitasion but now it doesn't work for large files as I said. I have to deal with the files as binary, for example :
Original file : 56 1F 32 1A 09 11 53 61 44 00 00 00 00 00 00 00
Temp file : 00 00 00 00 00 00 00 00 00 52 12 0C 7F A1 89 02
Output : 56 1F 32 1A 09 11 53 61 44 52 12 0C 7F A1 89 02
Where is my mistake :
Thanks in advance
Original file : 56 1F 32 1A 09 11 53 61 44 00 00 00 00 00 00 00
Temp file : 00 00 00 00 00 00 00 00 00 52 12 0C 7F A1 89 02
Output : 56 1F 32 1A 09 11 53 61 44 52 12 0C 7F A1 89 02
Where is my mistake :
Code:
Private Sub Command1_Click()
CommonDialog1.InitDir = App.Path
CommonDialog1.Filter = "Original Incomplete File|*.*"
CommonDialog1.ShowOpen
txtFile.Text = CommonDialog1.FileName
End Sub
Private Sub Command2_Click()
CommonDialog1.InitDir = App.Path
CommonDialog1.Filter = "Temp File|*.tmp"
CommonDialog1.ShowOpen
txtFile2.Text = CommonDialog1.FileName
End Sub
Private Sub StartMerge_Click()
Dim file_name As String
Dim file_length As Currency
Dim fnum As Long
Dim org() As Byte
file_name = txtFile.Text
file_length = FileLen(file_name)
Dim file_name2 As String
Dim file_length2 As Currency
Dim fnum2 As Long
Dim tmp() As Byte
file_name2 = txtFile2.Text
file_length2 = FileLen(file_name2)
Dim array_dimension As Long
array_dimension = file_length \ 100
Dim i As Long
Dim j As Long
For i = 0 To 99
ReDim tmp(1 To array_dimension) As Byte
ReDim org(1 To array_dimension) As Byte
fnum2 = FreeFile
Open file_name2 For Binary As #fnum2
Get #fnum2, ((i * array_dimension) + 1), tmp
Close fnum2
fnum = FreeFile
Open file_name For Binary As #fnum
Get #fnum, ((i * array_dimension) + 1), org
Close fnum
For j = 1 To array_dimension
If tmp(j) > 0 Then org(j) = tmp(j)
Next j
fnum = FreeFile
Open file_name For Binary As #fnum
Put #fnum, ((i * array_dimension) + 1), org
Close fnum
Next i
MsgBox "Original and Temp files have been merged successfuly", vbOKOnly, "Done"
End Sub