# Problem with simple math in auto it

## Recommended Posts

I'm working on getting the progress of an upload to a website, I copy and pasted the string I'm working with:

'00:00:00 (1.43 KB of 10.00 MB)'

and am using that to figure out the code this is what I came up with:

```\$Base = '00:00:00 (1.43 KB of 10.00 MB)'
\$Transfered = StringTrimLeft(\$Base, StringInStr(\$Base, '('))
\$Transfered = StringLeft(\$Transfered, StringInStr(\$Transfered, ' '))
\$Total = StringTrimLeft(\$Base, StringInStr(\$Base, 'of ')+2)
\$Total = stringLeft(\$Total, StringInStr(\$Total, ' '))
\$Progress = (\$Total / \$Transfered) * 100
MsgBox(0,'',\$Progress)```

all its returning is: -1#IND

I also tried to round \$Transfered & \$Total and it would always return 0, I'm sure it's something stupid, any ideas?

##### Share on other sites

I'm working on getting the progress of an upload to a website, I copy and pasted the string I'm working with:

'00:00:00 (1.43 KB of 10.00 MB)'

and am using that to figure out the code this is what I came up with:

```\$Base = '00:00:00 (1.43 KB of 10.00 MB)'
\$Transfered = StringTrimLeft(\$Base, StringInStr(\$Base, '('))
\$Transfered = StringLeft(\$Transfered, StringInStr(\$Transfered, ' '))
\$Total = StringTrimLeft(\$Base, StringInStr(\$Base, 'of ')+2)
\$Total = stringLeft(\$Total, StringInStr(\$Total, ' '))
\$Progress = (\$Total / \$Transfered) * 100
MsgBox(0,'',\$Progress)```

all its returning is: -1#IND

I also tried to round \$Transfered & \$Total and it would always return 0, I'm sure it's something stupid, any ideas?

That's a divide by zero error. Your divisor is a string, which evaluates to 0. Try this:
```\$Transfered = Number(\$Transfered)
If \$Transfered <> = 0 Then
\$Progress = (\$Total / \$Transfered) * 100
Else
MsgBox(16, "Error", "Operation not allowed:  Successfull divide by zero would destroy the space-time continuum!")
EndIf```

P.S. Number() conversion is required on \$Total also, so you could just do:

```\$Base = '00:00:00 (1.43 KB of 10.00 MB)'
\$Transfered = StringTrimLeft(\$Base, StringInStr(\$Base, '('))
\$Transfered = StringLeft(\$Transfered, StringInStr(\$Transfered, ' '))
\$Total = StringTrimLeft(\$Base, StringInStr(\$Base, 'of ')+2)
\$Total = stringLeft(\$Total, StringInStr(\$Total, ' '))

\$Progress = (Number(\$Total) / Number(\$Transfered)) * 100
MsgBox(0,'',\$Progress)```
Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

## Create an account

Register a new account