I have never asked this before for strange reasons
BUT now i will because i am to stupid to figure how to do that .
Let say i want load file big let say 2MB and show proceess of loading
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?
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
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.
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.
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,
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
add 1 more ?
heck ..looking silli
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!
thanks andy again..
i really have stupid problem with this percents
ok i will try ...
No problem, I will have a go at writing something for you.
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.
Don't worry Andy
No need to hurry ...here is so damn hot -- heat wave
cca 40 'C
wow thanks man
program is excellent
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
if iswindowclosed(w1) then breakfor ' check WM_CLOSE
wait 1 ' peekMessage
that one is a really strange construction
Everything else is great ;)
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!
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