Jump to content

Calculating the % of a number for a progress bar


 Share

Recommended Posts

Ok, this is for future ref.

I will use building a file shredder as an example.

#include<File.au3>

$lines = _FileCountLines( "C:\users\ect")
$currentline = 0

For $currentline = 1 To $lines Step 1
    _FileWriteToLine( "c:\users\ect", "0000000000000000000000", 1)
Next

Exit

If I wanted to add a progress bar to the process, I would need to be able to calculate what line it is out of 100.

This would be easy if the file was exactly 100 lines long, but I hardly think you would ever find a file that is exactly 100 lines.

What equasion might I use to calculate the % complete, and put that in a verable that the progress bar can use?

Thanks all.

Sorry if I have not explained this well enough.

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

Yes. As saying a Jos :)

Example:

#include <File.au3>

;$lines = _FileCountLines( "C:\users\ect")
$lines = 78
ProgressOn("Please wait..", "Writing strings", "", -1, -1, 16)

For $i = 1 To $lines
    ;_FileWriteToLine( "c:\users\ect", "0000000000000000000000", 1)
    $percent = Round($i / $lines * 100)
    ProgressSet($percent, $percent & "% done")
    Sleep(100)
Next

ProgressSet(100, "Done")
Sleep(1000)
ProgressOff()

Exit
Link to comment
Share on other sites

  • 3 weeks later...

Thanks guys. This is exactly what I was looking for. :)

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...