VB making a progress bar go up automatically whilst the program checks a database

I'm new to coding but when my program checks a database it takes a long time. My client wants a progress bar which goes up as the program runs through the code so he can see how long he has to wait.

I tried adding this code into the program in random places " ProgressBar.Value += 10" however it didn't get the affect I wanted.

How do I create a progress bar which automatically goes up based on how far the program is through the code?

1 answer

  • answered 2017-01-11 14:22 Dan_J

    Since you tagged Visual Studio, I'm guessing that you are using VB.Net and not VBA.

    Set the ProgressBar.Min to Zero, and ProgressBar.Max to the number of records that need processing. Then for each loop, add one to ProgressBar.Value.

    Finally, if the display is not updating, it's because the database operating is not giving the CPU a chance to re-draw the progress bar with the new value. You'll need to add Application.DoEvents to give the CPU a chance to re-draw the progress bar.

    Note that doing that will slow down the whole operation, so you might only want to do Application.DoEvents for every 10 records.