Solved

progress bar

Posted on 2013-05-23
6
421 Views
Last Modified: 2013-06-20
I am using the following code for my progress bar.  It increments as progress is made but when it gets to the end of the cycle the green progress indicator is not all the way to the end. Why?


Dim percentage As Integer
For i As Integer = 1 to TotalCount

    ' ... some work ...

    percentage = i / TotalCount * 100
    ProgressBar1.Value = percentage ' <-- assuming default Min = 0, Max = 100
    Application.DoEvents()
Next
0
Comment
Question by:vbnetcoder
6 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 39191027
I'd bet because of rounding. Instead of doing a percent, set Max to whatever the max number of items are and increment value accordingly and see if it works.
Also try outputting the value of percentage to see if it every reaches 100.
0
 
LVL 1

Expert Comment

by:dbote
ID: 39192130
Not sure but your calculation of....

percentage = i / TotalCount * 100

Should be

percentage = (i / TotalCount) * 100
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 39192307
Since division and multiplication are equal in the order of precedence for operators, the equation will be evaluated from left to right.  Your addition of parenthesis is changing nothing but aesthetics!...  =)
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Expert Comment

by:dbote
ID: 39192453
True.  Sorry.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 39197883
First of all, why all these percentage manipulations. Simply set the Maximum to TotalCount before going into the loop, and the following will work a little faster because it does not need to multiply and divide:

    ProgressBar1.Maximum = TotalCount
    For i As Integer = 1 To totalcount

      ' ... some work ...

      ProgressBar1.Value = i
      Application.DoEvents()
    Next

Anyway, I tested your code as is, and it works flawlessly. The Progress Bar is filled when finished, although the last block might end up being smaller than the other ones because the width of the control might not leave enough space.

I suspect that your problem might be in   ' ... some work ...

Have you checked to make sure that after the loop. ProgressBar1.Maximum and percentage are at the same value? Is it possible that there is an Exit For somewhere in the loop?
0
 

Author Closing Comment

by:vbnetcoder
ID: 39263318
ty
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What's the most efficient way to load up a couple of large table in C#? 5 39
coded character set iptc field within a jpeg 1 71
Tool Box 2 35
vb.net checkbox 7 41
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now