|
-
May 2nd, 2000, 10:09 PM
#1
Thread Starter
Hyperactive Member
Can anyone tell me how to use the percentage bar while copying files. The files i am copying within VB a large, so i would like to have some feedback to the copy process and how far it is going.
Regards
-
May 3rd, 2000, 12:07 AM
#2
Fanatic Member
Mmmmm.
If you are using the FileCopy command or sometinhg similar, execution will stop at that line until the command is completed. So you will not be able to update a progress bar or anything.
Maybe someone out there knows how to do this, i don't.
All i can suggest is that you write your own copy function. As an example. You could set the progress bars Max property to the size of the file being copied. You then copy the file in chunks. Every time you copy a chunk, you update the progress bars value by the size of the chunk being copied. I know this is a pain in the arse, but i don't know a better way.
Maybe someone else does?
Iain, thats with an i by the way!
-
May 3rd, 2000, 04:28 AM
#3
transcendental analytic
It's pain in your arse indeed. But you can make those chunks to 100 for every file and it will give you an update for each %. Open the files in binary, and dump the chunks in variable length string by using Get and Put statement. Also you may search for an activeX
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 3rd, 2000, 04:01 PM
#4
Thread Starter
Hyperactive Member
percentage bar
Do you have any sample code for that..? this is quite new too me.
-
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!
-
May 3rd, 2000, 05:20 PM
#6
Thread Starter
Hyperactive Member
percentage bar
What component or reference in the percentage bar, i do not seem to have it on my components list?
Regards
-
May 3rd, 2000, 05:24 PM
#7
Fanatic Member
Go to the Project menu in VB. Select Components. Now tick the "Microsoft Windows Common Controls 6.0". Now click ok. The progress bar should be on the toolbox now.
Iain, thats with an i by the way!
-
May 3rd, 2000, 05:31 PM
#8
Thread Starter
Hyperactive Member
percentage bar
I've found the percentage bar, but what about the path for the readable files.?
-
May 3rd, 2000, 05:37 PM
#9
Fanatic Member
I dont' know exactly what you mean.
if you only type in a file name, and no directory, the program will look for th file in the directory it is runnig in. e.g. if you type "myInputFile.txt" and your project is in "c:\myProject" then the path is c:\myProject\myInputFile.txt
Or you can specify the complete path. e.g. c:\someFolder\myOutputFile.txt
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
|