The main function that my second method uses:
Public Function SplitFile(SplitFileName As String, BeginningNumber As Long, ReturnErrorDes As String, Split As Long, oName As String) As Boolean
'Use this function to do file spliting. The function return a boolean value, true for successful, false for fail.
'The function has 4 parameters, i.e. the file name of the split file, the begin number, the file size of the generated file after split,
'and the generated file name after split
'After split, it will just generate the last 2 files in the disk, but ignoring all the other files, becasue only the last 2 files are useful to us.
Dim SaveName As String 'the generated file name after split
Dim fnum As Integer, fnum1 As Integer 'file channel variant
SplitFile = True 'if all does ok, then return true
On Error GoTo CleanUp
Dim CurrentFile As SectionedFile, m_lngNumFil As Long, m_LngLoop As Long, FilesLen As Long
FilesLen = FileLen(SplitFileName) 'get the file size of the generated file after slit
If FilesLen <= Split + 1 Then
SplitFile = False
ReturnErrorDes = "the new file size is too large, plese set it again!"
Exit Function
End If '
fnum = FreeFile 'return the first idle channel to read
Open SplitFileName For Binary As fnum 'open the source file by binary method
If CInt(FilesLen / Split) >= FilesLen / Split Or CInt(FilesLen / Split) = FilesLen / Split Then
m_lngNumFil = CInt(FilesLen / Split)
Else
m_lngNumFil = CInt(FilesLen / Split) + 1
End If 'calculate the number of the files that will generated after split
ReDim CurrentFile.Files(1) 'assign a Ems memory associated array
For m_LngLoop = 1 To m_lngNumFil
'this loop do the split work, and generate the files after split
If m_LngLoop < m_lngNumFil Then 'if not the last loop
ReDim CurrentFile.Files(1).Bytes(1 To Split)
're-assign the EMS memory array as the size of the split size
Get #fnum, , CurrentFile.Files(1).Bytes
'read binary data as the split size into the EMS memory array
Else 'if it the last loop
ReDim CurrentFile.Files(1).Bytes(1 To FilesLen - ((m_lngNumFil - 1) * Split))
're-assign the EMS memory that the same size as the lefted
Get #fnum, , CurrentFile.Files(1).Bytes
Close #fnum 'close the file reading channel
End If
'minus 2 for only generate the last 2 file, ignoring all the other files
If m_LngLoop > m_lngNumFil - 2 Then
SaveName = oName & "." & Format(BeginningNumber - 1 + m_LngLoop, "00#") 'calculate the generated file name, the extend name is 00x
fnum1 = FreeFile 'get the second idle channel to do writing
Open SaveName For Binary As fnum1
Put #fnum1, 1, CurrentFile.Files(1)
DoEvents
Close #fnum1 'writing the generated file by binary method
End If
Next
Exit Function
CleanUp: 'if it has exceptions
ReturnErrorDes = Err.Description
SplitFile = False 'return false
End Function
Vincent
---------------------
If u think u can, then u can!