Jump to content
Sign in to follow this  
AcidCorps

Problem with simple math in auto it

Recommended Posts

AcidCorps

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 this post


Link to post
Share on other sites
PsaltyDS

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

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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.