|
-
Mar 24th, 2006, 04:48 AM
#1
Thread Starter
Lively Member
[RESOLVED] Showing copying progress in a Label
Hey,
I'm making an application that copies files from one folder to another.
I want the copying progress shown in a label, just like in DOS when you copy files you'll see something like this:
folder\link.url
folder\Readme.txt
folder\setup.exe
folder\site.htm
4 file(s) copied.
I've come this far:
VB Code:
Option Explicit
Dim a As Integer
Dim b As Integer
Dim Destination As String
Private Sub Command1_Click()
Destination = "C:\Temp-1"
b = File1.ListCount - 1
For a = 0 To b
Label1.Caption = Label1.Caption & vbCrLf & "Copying: " & File1.List(a)
FileCopy File1.List(a), Destination & "\" & File1.List(a)
Next
End Sub
This works fine, yes, but now the text is shown in Label1 after all files have been copied. So my question is:
How can I make it show the current file that is being copied? Like this:
(When it's copying file1.txt):
Copying: file1.txt
(When file1.txt is copied and it's copying file2.txt):
Copying: file2.txt
If I didn't explain clear enough, just ask
-
Mar 24th, 2006, 05:34 AM
#2
Re: Showing copying progress in a Label
Welcome to the Forum rade 
You probably need a DoEvents,try:
VB Code:
Option Explicit
Dim a As Integer
Dim b As Integer
Dim Destination As String
Private Sub Command1_Click()
Destination = "C:\Temp-1"
b = File1.ListCount - 1
For a = 0 To b
DoEvents '<<<<<<<<<<< Added
Label1.Caption = Label1.Caption & vbCrLf & "Copying: " & File1.List(a)
FileCopy File1.List(a), Destination & "\" & File1.List(a)
Next
End Sub
This needs to be optimizd too.
Last edited by Bruce Fox; Mar 24th, 2006 at 05:42 AM.
-
Mar 24th, 2006, 05:40 AM
#3
Re: Showing copying progress in a Label
Now, to otimize (you may need to playwith the value), try:
VB Code:
If a Mod 2 = 0 Then DoEvents
Note: Change the Value of 2 to suit (Eg 5)
-
Mar 24th, 2006, 06:12 AM
#4
Re: Showing copying progress in a Label
DoEvents can slow the process down, and if you use Bruce's suggestion to call DoEvents just once every x times, the label will not be refreshed every time.
If you just want the label to be repainted, use the refresh method of the label. This will also slow it down a bit, but not as much as DoEvents can do.
VB Code:
Option Explicit
Dim a As Integer
Dim b As Integer
Dim Destination As String
Private Sub Command1_Click()
Destination = "C:\Temp-1"
b = File1.ListCount - 1
For a = 0 To b
Label1.Caption = Label1.Caption & vbCrLf & "Copying: " & File1.List(a)
Label1.Refresh
FileCopy File1.List(a), Destination & "\" & File1.List(a)
Next
End Sub
EDIT: and if you want to use DoEvents, you should call it after the label's caption is changed, and not before. Otherwise the caption is displayed after the file is copied.
-
Mar 24th, 2006, 06:24 AM
#5
Thread Starter
Lively Member
-
Mar 24th, 2006, 06:27 AM
#6
Thread Starter
Lively Member
Re: Showing copying progress in a Label
 Originally Posted by Bruce Fox
Welcome to the Forum rade 
Thanks Bruce These forums seem really good and useful.
-rade
"Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
- Linus Torvalds
-
Mar 24th, 2006, 06:40 AM
#7
Re: Showing copying progress in a Label
FransC is right, there is a place for .Refresh. There is also a place for DoEvents...
especially when you may want to abort a Loop with the click of a button - that is when it is helpful.
In any case, you have what you need, good luck with your app, and hope to see you as a regular here
-
Mar 24th, 2006, 06:46 AM
#8
Thread Starter
Lively Member
Re: Showing copying progress in a Label
Thanks again Bruce But I think you missed my little question there:
How do I add a scrollbar to the label? (Please don't tell it isn't possible  )
"Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
- Linus Torvalds
-
Mar 24th, 2006, 06:56 AM
#9
Re: Showing copying progress in a Label
 Originally Posted by rade
How do I add a scrollbar to the label? (Please don't tell it isn't possible  )
I'm being completely serious. It isn't possible.
-
Mar 24th, 2006, 07:20 AM
#10
Thread Starter
Lively Member
Re: Showing copying progress in a Label
 Originally Posted by Hack
I'm being completely serious. It isn't possible.
Well.. Any suggestions how I could do this? The largest amout of files that will be copied is between 10 and 15, but the label the progress is shown on only has place for 7 rows. Yes, it would be easiest to make the label higher, but then it would be all too big.
Can you come up with any way of "autoscrolling" the label or something similar? Or maybe there is another object, in which it is possible to include a scrollbar, that I could use for this instead of a label?
Any help is highly approcieted 
rade
Last edited by rade; Mar 24th, 2006 at 07:22 AM.
Reason: Typo
"Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
- Linus Torvalds
-
Mar 24th, 2006, 07:24 AM
#11
Re: Showing copying progress in a Label
You cans use a text box instead of a label, and just disable the input for it.
Or, use a listbox to show the "history" of what you are doing.
-
Mar 24th, 2006, 07:24 AM
#12
Re: Showing copying progress in a Label
The Label control is one of the most difficult controls to manipulate because it does not have a hWnd property. The functionality of a label, as it is, is what you get.
There have been a number of times when I needed more functionality that I knew I could get out of a label so I used a textbox (which does have an hWnd property). I set the textbox borderstyle to None, and its backcolor to the same backcolor as my form. This gave it the "look" of a label. But, because it was actually a textbox, I could do things with it that I couldn't with a label.
Like add scrollbars.
-
Mar 24th, 2006, 07:34 AM
#13
Thread Starter
Lively Member
Re: Showing copying progress in a Label
Alright! Thanks a lot guys, this was really really helpful! Man I love these forums 
I changed the label to a textbox => Problem Resolved
"Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
- Linus Torvalds
-
Mar 24th, 2006, 07:39 AM
#14
Re: Showing copying progress in a Label
 Originally Posted by rade
Alright! Thanks a lot guys, this was really really helpful! Man I love these forums
I changed the label to a textbox => Problem Resolved
A couple of additional things that you will want to do.
Set the Locked property of the textbox to True. That way, like a label, you can't actually type in it. Also, you don't want the blinking cursor to show when the textbox has focus, so use this API to hide it.
VB Code:
Private Declare Function HideCaret Lib "User32" (ByVal hWnd As Long) As Long
Private Sub Text1_GotFocus()
HideCaret Text1.hWnd
End Sub
-
Mar 24th, 2006, 08:26 AM
#15
Thread Starter
Lively Member
Re: [RESOLVED] Showing copying progress in a Label
Okay thanks again
"Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
- Linus Torvalds
-
Mar 24th, 2006, 09:16 AM
#16
Re: [RESOLVED] Showing copying progress in a Label
Give that man a rating, full of useful info !
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
|