# Calculating the % of a number for a progress bar

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

##### Share on other sites

something like :

`\$currentline/\$lines *100`

Live for the present,
Dream of the future,
Learn from the past.

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

##### Share on other sites

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.

## Create an account

Register a new account

×

• Wiki

• Back

• Git