Jump to content

Progress bar help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
mholt

mholt

    Newbie

  • Members
  • PipPip
  • 27 posts
Hey,

I'm working on a simple backup utility. I have a progress bar to indicate current progress. As the backup runs, it should be updating the progress bar.

I figure the most accurate way to do it is to fill it by how many bytes have been backed up, whether in MB, KB, or GB...

The problem is that the progress bar's Value property only accepts integers. Okay, so I could measure it in bytes - that'll always be a whole number.
s
Problem here is that sometimes the number of bytes being backed up exceeds the INT maximum value, thus the progress bar throws an exception.

How can I bring the number down to a usableize? I'm assuming a simple ratio would do it:


bytes currently backed up / total bytes = x / max INT value

With x being what we put as progressBar1.value... thus:

x = max INT value * (bytes currently backed up / total bytes)

The problem is, what if I have a lot of small files in the backup? It would always just equal zero when rounded down, and the progress bar would never increase. Should I use a member variable of type double and just store the sum up to the point where it can increase the value of the p. bar, then reset that value to 0?

Is there an easier way to do this?

#2
bvaessen

bvaessen

    Newbie

  • Members
  • PipPip
  • 27 posts
Just use two progressbars, like a lot of other programs do: one for the currently backed up file, and one for the overall progress. For ech new file, you should set the max value accordingly.

Also, why not work with percentages? You can always print the amount of MB processed as a label.

About floats: you can multiply your float by 1000 e.g., and then round it to an integer. That way you don't loose all accuracy, but do have an integer to calculate with. If you need the float back, you divide it by 1000 again.

Launch-IT :: Home
Ben Vaessen :: Home

#3
VCKicks

VCKicks

    Newbie

  • Members
  • PipPip
  • 24 posts
I agree, don't set the value of the progressbar to the total bytes processed, that's not what it's meant for. Stick with a percentage.
Visual C# Kicks - Everything C#.NET programming related