|
-
Mar 24th, 2005, 03:56 PM
#1
Thread Starter
Hyperactive Member
progress bar glitch [RESOLVED]
Hi all,
I have a progress bar that displays when files are bieng added to a folder but instead of the progress bar being displayed in a way that it goes up in squares it just seems to be there and doesnt display until the files are added.
heres my code
VB Code:
Private Sub Command1_Click()
Dim i As Integer
ProgressBar1.min = 0
'ProgressBar1.Max = 100
ProgressBar1.Value = 0
ProgressBar1.Scrolling = ccScrollingSmooth
Dim strFile() As String, strPath As String
Dim n As Long, nCount As Long
On Error Resume Next
With CommonDialog1
CommonDialog1.Filter = "MP3 Files|*.mp3" 'Only Show MP3 type files in folder
.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNLongNames
.CancelError = True
.InitDir = "C:\"
.DialogTitle = "Select File To Add To Playlist"
.ShowOpen
If Err.Number <> cdlCancel Then
strFile = Split(.FileName, vbNullChar)
nCount = UBound(strFile)
If nCount = 0 Then
'Only one file is selected so split up the path and the filename
ReDim strFile(1)
strFile(0) = Left$(.FileName, InStrRev(.FileName, "\"))
strFile(1) = Mid$(.FileName, InStrRev(.FileName, "\") + 1)
nCount = 1
End If
strPath = strFile(0)
If Right$(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
ProgressBar1.Max = nCount
For n = 1 To nCount
If Len(Dir(FAVORITES_FOLDER & strFile(n))) = 0 Then
FileCopy strPath & strFile(n), FAVORITES_FOLDER & strFile(n)
End If
ProgressBar1.Value = nCount
Next
End If
End With
End Sub
any suggestions
Thanks
R
Last edited by robvr6; Mar 24th, 2005 at 07:38 PM.
-
Mar 24th, 2005, 04:03 PM
#2
Re: progress bar glitch
You probably don't need the progress bar unless there are more than 100 songs to be added. Play around with it to see. The files get added quickly, that's why the bar jumps.
-
Mar 24th, 2005, 04:05 PM
#3
Re: progress bar glitch
Well you set the value to nCount in the loop instead of using n. Perhaps you might also need to refresh the progressbar
VB Code:
For n = 1 To nCount
If Len(Dir(FAVORITES_FOLDER & strFile(n))) = 0 Then
FileCopy strPath & strFile(n), FAVORITES_FOLDER & strFile(n)
End If
ProgressBar1.Value = [b]n[/b]
ProgressBar1.Refresh
Next
-
Mar 24th, 2005, 05:01 PM
#4
Re: progress bar glitch
I would also add a DoEvents in the loop somewhere
-
Mar 24th, 2005, 05:07 PM
#5
Re: progress bar glitch
 Originally Posted by moeur
I would also add a DoEvents in the loop somewhere
I don't think that is necassary as long as he refreshes the progress bar.
-
Mar 24th, 2005, 05:28 PM
#6
Re: progress bar glitch
I must be in an argumentative mood today, Joacim.
If you don't add a DoEvents call inside the loop, then the form will not repaint when it needs to. If the file copying is taking a long time, and you cover part of your form with another app, then everything will dissapear. and won't come back until file copying is over.
-
Mar 24th, 2005, 05:37 PM
#7
Thread Starter
Hyperactive Member
Re: progress bar glitch
Thats what seems to be happening it the app disapperars while the files are bieng added. Another point you mentioned adding a large number of songs but currently I am only able to add about 12. Am I missing something.
Thanksn
R
-
Mar 24th, 2005, 05:56 PM
#8
Re: progress bar glitch
 Originally Posted by moeur
I must be in an argumentative mood today, Joacim.
If you don't add a DoEvents call inside the loop, then the form will not repaint when it needs to. If the file copying is taking a long time, and you cover part of your form with another app, then everything will dissapear. and won't come back until file copying is over.
Calling the Refresh method will repaint the progress bar...
-
Mar 24th, 2005, 06:31 PM
#9
Re: progress bar glitch
Calling the Refresh method will repaint the progress bar...
I don't think Refresh will help much. Try the following example
VB Code:
Private Sub Command1_Click()
Dim i As Long, j As Long
With ProgressBar1
.Max = 10000
For i = .Min To .Max
'do long synchronous task
For j = 1 To 100000
Next j
.Value = i
.Refresh
'You should put DoEvents here
Next i
End With
End Sub
As long as you don't touch anything everything is OK, in fact you don't even need the Refresh method. But now run the program and while it is progressing, cover part of the form with another window such as Calculator and the form won't repaint and the progressbar will stop progressing.
-
Mar 24th, 2005, 06:32 PM
#10
Re: progress bar glitch
OK.. if you say so
-
Mar 24th, 2005, 07:08 PM
#11
Thread Starter
Hyperactive Member
Re: progress bar glitch
Thanks Joacim your method worked excellent for my progress bar - just one more thing like I mentioned before I can only add a maximun of three files - do you have any suggestions why this is happening and how I may combat it.
Thanks
R
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
|