February 27, 2024, 01:48:28 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Progress bar percentage?

Started by aurelCB, July 04, 2021, 09:51:00 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aurelCB

July 04, 2021, 09:51:00 AM Last Edit: March 04, 2023, 02:27:52 AM by aurelCB
-

Andy

July 04, 2021, 08:58:19 PM #1 Last Edit: July 05, 2021, 04:47:01 AM by Andy
Hi Aurel,

No questions are stupid, how else do we learn!

What ever the size of file is that's your 100 %.

I would use GetFileSize or something to convert your 2MB to bytes first.

Here is an example by Fasecero
http://www.ionicwind.com/forums/index.php?topic=6271.msg45994#msg45994

Divide 2MB (2097152 bytes) by 100 = 20971.52

20971.52 is your 1% of 2MB

So it would take 100 x 20971.52's to give you your 2MB.


Now you can have a progress bar going from 0 to 100, all you would need to do is to see how big the file is on disk compared to the original file or how much you have processed it.

Example:

You want to download 2MB (2097152 bytes).

Your 1 % is 20971.52

Amount downloaded so far is 1048576 bytes.

Divide 1048576 by 20971.52 = 50% (1MB) = 50 on your progress bar.

As long as you have your 1% size you can check it against any amount.

Formula:

Actual size of file in bytes / 100 = X (1%)
Progress in bytes / X (1%) = Progress position of your progress bar e.g. 24%

Hope that helps,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

July 06, 2021, 08:22:18 PM #2 Last Edit: July 06, 2021, 11:35:28 PM by Andy
Aurel,

No problem.

No, you need to half it.

Let's amend the formula a little to this:

Actual size of file in bytes / Progress bar size = X
Progress in bytes / X = Progress position of your progress bar.

In my original reply we needed to find 1% - why?

Us humans are used to say downloading a file, and when we do we understand straight away the following...

0% = Nothing downloaded yet.
50% = half of it downloaded.
100% = all of it downloaded.

and to calculate those percentages we need to know our 1%, otherwise we could not calculate how much has been done.


Changing the progress bar size:

Now, if we want the progress bar to be bigger or smaller than 100 you need to understand what's going on, and how as a human we can understand how much has been done.

Example - Progress bar 0 - 200

Take your file size in bytes 2097152 (2MB)
Now divide it by 200 (progress bar size) = X = 10485.76


What does 10485.76 represent as a %?

It means that 10485.76 is 0.5%.
Because the progress bar is now double in size X becomes half of 1%.

The more you increase the progress bar above 100, the smaller X becomes.

X is now 1 / 200th

So although we might have downloaded 1048576 (10485.76 * 100) it still only makes 50% of the whole file not 100% as we need 200 of them this time.

That is 200 / 100 = 50%

Best advice from me:

I can only speak for myself, but I would bet most would agree it's best to keep a progress bar to 100, it's so much easier to work out when you only have 2 brain cells like me!

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Aurel,

No problem, I will have a go at writing something for you.

Andy.
 :)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Aurel,

Okay, think I have this right for you.

Play around with the numbers etc, only tried this on 1MB & 2MB and progress range 100 & 200.

Hope this helps.

Attached.
Andy.
 :)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

July 09, 2021, 02:45:46 AM #5 Last Edit: July 09, 2021, 03:14:37 AM by Andy
Aurel,

No problem, always here to help if I can.

The include file I always add, it's just a habit.

As for the DOUBLE's, I honestly can't remember why, think I was checking percents e.g. 12.27%, was just trying to write you something quickly for you to use.

I originally had OPENCONSOLE in the program, it was just a way to break out of the FOR / NEXT loop if the window had been closed to exit the program.

Yes, it's hot here too so I know how you feel!

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

billhsln

I think I can answer the question about DOUBLE.  Thru some testing and trials of different things testing FLOAT and DOUBLE, it turns out that using DOUBLE gives better results.  Sorry, I don't remember why, but I would bet there is a forum message about it some where.

Did a quick search:  http://www.ionicwind.com/forums/index.php?topic=6482.msg47283#msg47283

Bill
When all else fails, get a bigger hammer.