Dim nLen As Double
Dim strFName As String
Dim b() As Byte
Private Sub cmdBrowse_Click()
dlg.ShowOpen
txtFile = dlg.FileName
strFName = dlg.FileTitle
End Sub
Private Sub cmdMerge_Click() ' merge previously splitted file to its split direcory
Dim n As Double: Dim i As Long: Dim bOpen As Boolean: Dim d As Double
For i = 0 To File1.ListCount - 1
If IsNumeric(Right(File1.List(i), 3)) Then
If Not bOpen Then
Open lblOut & "\" & Left(File1.List(i), Len(File1.List(i)) - 4) For Binary As 2
bOpen = True
End If
n = FileLen(lblOut & "\" & File1.List(i))
Open lblOut & "\" & File1.List(i) For Binary As 1
ReDim b(n - 1)
Get #1, , b()
Put #2, d + 1, b()
Close #1
d = d + n
End If
Next
Close #2
File1.Refresh
End Sub
Private Sub cmdSplit_Click() 'split file on two equal files
If Trim(txtFile) = "" Or Dir(txtFile) = "" Then
MsgBox "File doesn't exist"
cmdBrowse.SetFocus
Exit Sub
End If
If Val(txtSize) < 1 Then
MsgBox "Incorrect split size"
txtSize.SetFocus
Exit Sub
End If
On Error GoTo er1
lblOut = txtFile & "_split"
lblOut.Refresh
MkDir lblOut
File1.Path = lblOut
File1.Visible = True
txt.Visible = False
If cmb.ListIndex = -1 Then cmb.ListIndex = 2
Dim i As Long 'number of file
Dim ss As Double 'split size
If cmb.ListIndex = 0 Then
ss = 1024
ss = ss * 1024
ElseIf cmb.ListIndex = 1 Then
ss = 1024
Else
ss = 1
End If
ss = Round(Val(txtSize) * ss, 0)
nLen = FileLen(txtFile)
Open txtFile For Binary As 1
While nLen > ss
ReDim b(ss - 1)
Get #1, ss * i + 1, b()
Open lblOut & "\" & strFName & "." & Format(i, "000") For Binary As 2
Put #2, , b()
Close #2
File1.Refresh
i = i + 1
nLen = nLen - ss
Wend
ReDim b(nLen - 1)
Get #1, ss * i + 1, b()
Open lblOut & "\" & strFName & "." & Format(i, "000") For Binary As 2
Put #2, , b()
Close #2
File1.Refresh
Beep
Close #1
Exit Sub
er1:
Select Case Err
Case 75
If MsgBox("Split folder already exist. Would you like to overwrite it?", vbYesNo) = vbYes Then
Dim j As Long
File1.Path = lblOut
For j = File1.ListCount - 1 To 0 Step -1
Kill lblOut & "\" & File1.List(j)
Next
RmDir lblOut
Resume
Else
lblOut = "Output Directory"
End If
Case Else
MsgBox Err.Number & ": " & Err.Description
End Select
End Sub
Private Sub Form_Load()
cmb.ListIndex = 0
File1.Visible = False
End Sub