|
-
Sep 25th, 2000, 09:22 AM
#1
Thread Starter
Addicted Member
I want to put a progress bar in my project to show when files have copied over. I've been looking through previous posts but still don't really understand how to use them. Could someone please put me in the right direction.
Here is my code that copies the files. I've added the progress bar to my form. I just don't know how to use it.
Thanks for any help
JK
Code:
Public Sub CopyTheFiles()
Dim FSO As Object
On Error GoTo NOFSO
Set FSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
FSO.CopyFile "D:\Folder1\*.ack", MyNewDir, True
FSO.CopyFile "D:\Folder2\*.dec", MyNewDir2, True
FSO.CopyFile "D:\Folder3\*.gen", MyNewDir3, True
FSO.CopyFile "D:\Folder4\*.out", MyNewDir3, True
FSO.CopyFile "D:\Folder5\*.tan", MyNewDir4, True
FSO.CopyFile "D:\Folder6\*.Rtrg", MyNewDir5, True
MsgBox "The files have been Successfully Copied over”
Set FSO = Nothing
Exit Sub
NOFSO:
MsgBox "FSO CreateObject Failed, Copying of files"
End Sub
-
Sep 25th, 2000, 09:24 AM
#2
Fanatic Member
The Progressbar works easy, it has a few properties that you need:
Min - the smallest value you can give it
Max - the biggest value you can give it
Value - how far the progress is finished
Note: Don't forget to insert a doevents command, otherwise the progressbar will not draw
-
Sep 25th, 2000, 09:26 AM
#3
Fanatic Member
Example:
First add a progressbar and a command button to a form
Then, add this code to the command button
Code:
Progressbar1.Min = 1
Progressbar1.Max = 100
For i = 1 to 100
Progressbar1.Value = i
Doevents
Next
-
Sep 25th, 2000, 10:37 AM
#4
Thread Starter
Addicted Member
hi oetje
Thanks for the help. I've just got it to work in my project.
Cheers
JK
-
Sep 25th, 2000, 11:41 AM
#5
You might not want to call a DoEvents as this will let the system process all events, not just the progress bar refresh. You could call the ProgressBar1.Refresh method to just get the progress bar to refresh its image.
That said, if you want to have a cancel button then you will need the cancel button. You could have a cancel button like below...
Private Cancelled as Boolean
Private Sub DoCopy ()
Cancelled = False
PB.Min = 1
PB.Max = 100
For i = 1 to 100
'Do something clever...
PB.Value = i
If Cancelled then
'Clean up code to finish up
Exit For
End If
DoEvents
Next i
Msgbox "Finished!!"
End Sub
And have a button
Private sub cmdCancel_Click()
Cancelled = True
End Sub
Then when the user presses cancel, the actions will be stopped and you can get the app to 'nicely' go back as it was.
J.
-
Sep 25th, 2000, 01:44 PM
#6
Try this:
Code:
'Code from Megatron
Make a Form with a CommandButton, CommonDialog, Label and ProgressBar and put the following code into the Form.
Private Sub Command1_Click()
Dim Source As String
Dim Dest As String
Dim Data As String
Dim TransferRate As Integer
CommonDialog1.CancelError = True
CommonDialog1.Filter = "All Files|*.*"
CommonDialog1.ShowOpen
If Err <> 32755 Then
Source = CommonDialog1.filename
Dest = Source & " - Copy 2"
Open Source For Binary As #1
Open Dest For Binary As #2
ProgressBar1.Max = FileLen(Source)
TransferRate = 1024
Do Until LOF(1) = Loc(1) Or EOF(1)
Data = ""
If LOF(1) - Loc(1) < ChunkSize Then
Data = String(LOF(1) - Loc(1), 0)
Else
Data = String(ChunkSize, 0)
End If
Get #1, , Data
Put #2, , Data
Label1.Caption = Loc(1) & " bytes out of " & LOF(1) & " transfered"
If ProgressBar1.Value + TransferRate > FileLen(Source) Then Exit Do
ProgressBar1.Value = ProgressBar1.Value + TransferRate
Loop
End If
End Sub
you will be asked to search for the file in the CommonDialog.
When you find it, it will copy it as yourfilename - Copy2.
When it's copying, it will show the status with a Label and the ProgressBar.
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
|