|
-
May 3rd, 2000, 04:35 PM
#5
Fanatic Member
Here ya go.
This is a binary chunk copying program that i wrote a while ago, when i was helping someone else on this forum. It had a flaw in it earlier, but it works perfectly now.
I know for a fact that other people do it slightly differently to me, but give ten programmers the same problem and you will get 10 different solutions.
For this to work you need:
textBox called "txtInput"
textBox called "txtOutput"
textBox called "txtChunkSize"
commandButton called "cmdCopy"
progressBar called "ProgressBar1"
Then when the program runs enter the input file and the output file. Also enter the size of the chunks in bytes.
There is no error checking, so if a file doesn't exist it will crash, but you can sort that out.
Code:
Option Explicit
Dim CHUNK_SIZE As Long
Dim blCopying As Boolean
Private Sub cmdCopy_Click()
Dim i As Long
Dim iLength As Long, iMod As Long, iRemain As Long
Dim myFile As String, myOutFile As String
Dim myByte() As Byte
blCopying = True
myFile = txtInput.Text
myOutFile = txtOutput.Text
CHUNK_SIZE = txtChunkSize.Text
'open the files
Open myFile For Binary As #1
Open myOutFile For Binary As #2
'get the length
iLength = FileLen(myFile)
'find out how many time 1024 goes into iLength
iMod = iLength \ CHUNK_SIZE
'finds the remainder
iRemain = iLength Mod CHUNK_SIZE
ReDim myByte(CHUNK_SIZE - 1) As Byte
ProgressBar1.Max = iMod
ProgressBar1.Value = 0
'loop for however many times 1024 goes into the filelength
For i = 1 To iMod
Get #1, , myByte
Put #2, , myByte
Me.Caption = "Progress = " & Int(((i * CHUNK_SIZE) / iLength) * 100) & "%"
ProgressBar1.Value = i
DoEvents
If blCopying = False Then
'in case of close
Close #1
Close #2
Unload Me
Exit Sub
End If
Next i
'get the remaining charcters
If iRemain > 0 Then
ReDim myByte(iRemain - 1) As Byte
Get #1, , myByte
Put #2, , myByte
End If
ProgressBar1.Value = ProgressBar1.Max
Me.Caption = "Finished!"
Close #1
Close #2
blCopying = False
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'if the user tries to quit the program then we need
'to set a boolean to stop the loop
If blCopying = True Then
blCopying = False
End If
End Sub
Hope this helps.
Iain, thats with an i by the way!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|