Get Progress

Posts 1–3 of 3 · Page 1 of 1
Get Progress
My English is translated, Sorry

This function returns a percentage from 0% to 100% according to the value.

Example:
Code:
Dim progress As Integer = ( Current / 100) / ( Maximum / 100 / 100)
Example 2 ( Using ProgressBar ):
Code:
Dim progress As Integer = ( Progressbar1.Value / 100 ) / ( Progressbar1.Maximum / 100 / 100 )
I used it in a scan file, the maximum is the total of the files and the current is being scanned !
The progress variable will return a percentage value to 100%
She can be utilized to generate large percentage of values.

Credits
Code:
pDevice (done unintentionally but left what I wanted)
Efficiency question:

Dim progress As Integer = ( Current / 100) / ( Maximum / 100 / 100)
would result in.... 3 or 4 division operations? (see question at end of post)

I thought people calculate "percentage" as (current / maximum) * 100
ex. 1/10 = 10%

(1 / 10)* 100
.1 * 100 = 10
1 division operation and 1 multiplication.

Your way:
ex. 1/10 = 10%
(1 / 100) / (10 / 100 / 100)
(.01) / (.001)
== 10
3 or 4 div operations.

So your way works, but seems unnecessarily complex? (/100/100 LOOKS awkward) Is the div instruction faster than mul, where 4 divs would be faster than 1 div and 1 mul ?? Or is there another reason?

compiler person: would /100 / 100 get optimized out to (Maximum / 10000) and cut out a div operation, or no?
Quote Originally Posted by abuckau907 View Post
Efficiency question:

Dim progress As Integer = ( Current / 100) / ( Maximum / 100 / 100)
would result in.... 3 or 4 division operations? (see question at end of post)

I thought people calculate "percentage" as (current / maximum) * 100
ex. 1/10 = 10%

(1 / 10)* 100
.1 * 100 = 10
1 division operation and 1 multiplication.

Your way:
ex. 1/10 = 10%
(1 / 100) / (10 / 100 / 100)
(.01) / (.001)
== 10
3 or 4 div operations.

So your way works, but seems unnecessarily complex? (/100/100 LOOKS awkward) Is the div instruction faster than mul, where 4 divs would be faster than 1 div and 1 mul ?? Or is there another reason?

compiler person: would /100 / 100 get optimized out to (Maximum / 10000) and cut out a div operation, or no?
was a difficult but worked through and yes you are right can be optimized.
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us