Results 1 to 11 of 11

Thread: progress bar glitch [RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Resolved 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:
    1. Private Sub Command1_Click()
    2.  
    3.     Dim i As Integer
    4.  
    5.     ProgressBar1.min = 0
    6.     'ProgressBar1.Max = 100
    7.     ProgressBar1.Value = 0
    8.     ProgressBar1.Scrolling = ccScrollingSmooth
    9.  
    10.     Dim strFile() As String, strPath As String
    11.     Dim n As Long, nCount As Long
    12.     On Error Resume Next
    13.     With CommonDialog1
    14.         CommonDialog1.Filter = "MP3 Files|*.mp3"       'Only Show MP3 type files in folder
    15.  
    16.         .Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNLongNames
    17.         .CancelError = True
    18.         .InitDir = "C:\"
    19.         .DialogTitle = "Select File To Add To Playlist"
    20.      
    21.         .ShowOpen
    22.         If Err.Number <> cdlCancel Then
    23.             strFile = Split(.FileName, vbNullChar)
    24.             nCount = UBound(strFile)
    25.             If nCount = 0 Then
    26.                 'Only one file is selected so split up the path and the filename
    27.                 ReDim strFile(1)
    28.                 strFile(0) = Left$(.FileName, InStrRev(.FileName, "\"))
    29.                 strFile(1) = Mid$(.FileName, InStrRev(.FileName, "\") + 1)
    30.                 nCount = 1
    31.             End If
    32.             strPath = strFile(0)
    33.             If Right$(strPath, 1) <> "\" Then
    34.                 strPath = strPath & "\"
    35.             End If
    36.             ProgressBar1.Max = nCount
    37.             For n = 1 To nCount
    38.                 If Len(Dir(FAVORITES_FOLDER & strFile(n))) = 0 Then
    39.                     FileCopy strPath & strFile(n), FAVORITES_FOLDER & strFile(n)
    40.                 End If
    41.                 ProgressBar1.Value = nCount
    42.             Next
    43.         End If
    44.     End With
    45. End Sub

    any suggestions
    Thanks
    R
    Last edited by robvr6; Mar 24th, 2005 at 07:38 PM.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. For n = 1 To nCount
    2.     If Len(Dir(FAVORITES_FOLDER & strFile(n))) = 0 Then
    3.         FileCopy strPath & strFile(n), FAVORITES_FOLDER & strFile(n)
    4.     End If
    5.     ProgressBar1.Value = [b]n[/b]
    6.     ProgressBar1.Refresh
    7. Next

  4. #4
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: progress bar glitch

    I would also add a DoEvents in the loop somewhere

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: progress bar glitch

    Quote 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.

  6. #6
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    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

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: progress bar glitch

    Quote 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...

  9. #9
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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:
    1. Private Sub Command1_Click()
    2. Dim i As Long, j As Long
    3.  
    4. With ProgressBar1
    5. .Max = 10000
    6. For i = .Min To .Max
    7.     'do long synchronous task
    8.     For j = 1 To 100000
    9.     Next j
    10.     .Value = i
    11.     .Refresh
    12.     'You should put DoEvents here
    13. Next i
    14. End With
    15. 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.

  10. #10
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: progress bar glitch

    OK.. if you say so

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    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
  •  



Click Here to Expand Forum to Full Width