July 04, 2022, 03:41:44 AM

## 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

0 Members and 1 Guest are viewing this topic.

#### aurelCB

##### July 04, 2021, 09:51:00 AM
I have never asked this before for strange reasons
BUT now i will because i am to stupid to figure how to do that .
with progress control ..so how properly calculate size of file to size of my control
which can be let say 100 in size ?
Is there a simple formula for that?
forum for hobby programming:<br />https://aurelsoft.ucoz.com

#### 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:

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.

#### aurelCB

##### July 06, 2021, 11:22:24 AM #2
thanks Andy
little bit ..so according to you important fact is one percent to know
well i can agree with that
but how ..if my progress bar is let say 200 in size then i probably need
heck ..looking silli
forum for hobby programming:<br />https://aurelsoft.ucoz.com

#### Andy

##### July 06, 2021, 08:22:18 PM #3 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...

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%

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.

#### aurelCB

##### July 08, 2021, 02:35:21 AM #4
thanks andy again..
i really have stupid problem with this percents
ok i will try ...
forum for hobby programming:<br />https://aurelsoft.ucoz.com

#### Andy

##### July 08, 2021, 02:38:47 AM #5
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

##### July 08, 2021, 04:22:11 AM #6
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.

#### aurelCB

##### July 09, 2021, 12:44:28 AM #7
Don't worry Andy
No need to hurry ...here is so damn hot -- heat wave
cca 40 'C
forum for hobby programming:<br />https://aurelsoft.ucoz.com

#### aurelCB

##### July 09, 2021, 12:55:30 AM #8
wow thanks man
program is excellent

few questions:

1. include file ..there is no need my EBasic complain
and in general i tend to avoid Sapero includes

2.why is this two double floats
double filesize = 2097152 ' 2MB File size
double ProgressBarRange = 200 'Progress bar range

3
if iswindowclosed(w1) then breakfor  ' check WM_CLOSE

wait 1  ' peekMessage

that one is a really strange construction

Everything else is great
forum for hobby programming:<br />https://aurelsoft.ucoz.com

#### Andy

##### July 09, 2021, 02:45:46 AM #9 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

##### July 09, 2021, 11:42:50 AM #10
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.