CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2004
    Posts
    33

    Refresh progress bar?

    I'm using a progress bar to monitor a process that's retrieving a lot of data from a database. That process loops and updates the ProgressBar.Value property as it goes round.

    Problem is, i don't see anything happen. The progress bar is visible and when I step through the code I can see the value changing but nothing gets displayed. I've tried calling the form.refresh function but no banana.

    Is there anything else I need to do to get this thing working?

  2. #2
    Join Date
    Aug 2003
    Location
    Buenos Aires, Argentina
    Posts
    513
    Try using DoEvents:

    Code:
    Dim intCount As Integer
    
    ...
    
    ProgressBar1.Value = ProgressBar1.Value + 1
    
    For intCount = 1 To 100
        DoEvents
    Next
    
    Me.Refresh
    
    ...

  3. #3
    Join Date
    Jan 2004
    Posts
    33
    Sorry, you'll have to elaborate, i'm new to VB. Do you mean just putting in idle calculations to take up processor time and give it time to display?

    Or do you mean raising an event that causes the bar to refresh?

    IT's worth noting that the code that causes the bar to update is in a separate class to the form and calls a sub in the form to get it to update. Coudl this be the cause of my problems? The bar does update itself if I set the value in the form_load function.

  4. #4
    Join Date
    Aug 2003
    Location
    Buenos Aires, Argentina
    Posts
    513
    I mean putting in idle calculations to take up processor time and give it time to display.

    You have to place the code (not the Dim, it goes before) inside the code that loops.

    Code:
    Dim intCount As Integer
    
    While xxxxx 'Your loop
        ...
    
        ProgressBar1.Value = ProgressBar1.Value + 1
    
        For intCount = 1 To 100
            DoEvents
        Next
    
       Me.Refresh
    
       ...
    
    Wend

  5. #5
    Join Date
    Jan 2004
    Posts
    33
    Thanks for the help but still no luck. The progress bar refuses to be updated even though the value is clearly changing and i'm instructing it do do other stuff.

    I'm going to try and get it to update from within the form and see what the result is.

  6. #6
    Join Date
    Jan 2004
    Posts
    33
    I've created a function in the form that does the following

    Code:
    Public Sub UpdateProgressBar(iValue As Integer)
        
        prgHistoric.Value = iValue
        prgHistoric.Refresh
        Dim Count As Integer
        For Count = 1 To 100
            DoEvents
        Next
    
        'Me.Refresh
    End Sub
    If i call this from with form_load and give it a value of 20, then the progressbar loads up already initialised with a value of 20 that you can see.

    If i call the function from within another function in a separate class, using the syntax:

    Code:
    myform.UpdateProgressBar
    then nothing happens. Zippo. Progressbar value IS updated but it seems like the screen is not refreshed? I've tried calling both me.refresh and progressbar.refresh

    This is doing my head in!

  7. #7
    Join Date
    Aug 2003
    Location
    Buenos Aires, Argentina
    Posts
    513
    Call the Refresh method of the form after you call UpdateProgressBar:
    Code:
    ...
    UpdateProgressBar 20
    Me.Refresh
    ...

  8. #8
    Join Date
    Jan 2004
    Posts
    33
    Still nothing, this must be some sort of threading issue that i'm completely unaware of. It's as if the form is running in a completely separate process that's not getting any processor time regardless.

  9. #9
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    No refresh or doevents needed

    The ProgressBar does not need refresh or doevents.
    Ie:
    Attached Files Attached Files
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

Featured