It is currently April 26th, 2024, 1:48 pm

Calc: Division by 0 Error in Skin

Get help with creating, editing & fixing problems with skins
DavidFw1960
Posts: 42
Joined: December 27th, 2016, 1:32 am

Calc: Division by 0 Error in Skin

Post by DavidFw1960 »

I have a skin that is giving me an error in the log about dividing by zero. It does however calculate and display the correct percentage value in the ToolTip I am using to display it - so its not displayed on a meter.

The skin reads a xml file from my Internet Provider and it has to calculate the 3 variables in the below measure.

[PercentUsedData]
Measure=Calc
Formula=Round(((MeasureUploadedGB + MeasureDownloadedGB) * 100 / MeasureAllowanceGB),2)
DynamicVariables=1

So it's not causing a problem but I HATE errors so how do I get rid of this one?
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5406
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Calc: Division by 0 Error in Skin

Post by eclectic-tech »

You could try couple of ways to eliminate that error:

1.) Change your formula to:
Formula=Round(((MeasureUploadedGB + MeasureDownloadedGB) * 100 / (MeasureAllowanceGB+0.000001),2)

2.) Add Substitute="0":"0.000001" to [MeasureAllowanceGB] section.
This will require you to use the string value of the measure in your calc formula, so the substitution is used.
Formula=Round(((MeasureUploadedGB + MeasureDownloadedGB) * 100 / [MeasureAllowanceGB],2)
DavidFw1960
Posts: 42
Joined: December 27th, 2016, 1:32 am

Re: Calc: Division by 0 Error in Skin

Post by DavidFw1960 »

I like that first way..... didn't even think of that!
That got rid of the error. Thanks.

I was originally thinking to wait for it to be non-zero but this works too.
DavidFw1960
Posts: 42
Joined: December 27th, 2016, 1:32 am

Re: Calc: Division by 0 Error in Skin

Post by DavidFw1960 »

Incidentally I got an error with suggestion #2.

I also tried an IF condition to test if measure=0 and if it did to add the 0.000001 otherwise don't and got the same error.
Also changed the 3 variables which were calculated so they all use a value from the txt file (string) so not derived at all but a read in value.
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Calc: Division by 0 Error in Skin

Post by balala »

eclectic-tech wrote:2.) Add Substitute="0":"0.000001" to [MeasureAllowanceGB] section.
I think a better solution would be to add instead of a Substitute="0":"0.000001" option, the following two options:

Code: Select all

RegExpSubstitute=1
Substitute="^0$":"0.000001"
The major difference is that if only the Substitute="0":"0.000001" option is added, every 0 will be replaced and for example instead of 100, you'll get 10.0000010.000001, because the two 0s (second and third digits) are both replaced by 0.000001. Adding the RegExpSubstitute=1 option (and modifying properly the Substitute option), ensures that the replacement is done only if the number doesn't have other digits beside the 0.
DavidFw1960
Posts: 42
Joined: December 27th, 2016, 1:32 am

Re: Calc: Division by 0 Error in Skin

Post by DavidFw1960 »

Tried that. Still divide by zero error.
First solution works.
Thanks anyway.
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Calc: Division by 0 Error in Skin

Post by balala »

DavidFw1960 wrote:Tried that. Still divide by zero error.
First solution works.
Thanks anyway.
I don't think so. Have you took into account eclectic-tech's suggestion (I marked red the most important part of his reply):
eclectic-tech wrote:2.) Add Substitute="0":"0.000001" to [MeasureAllowanceGB] section.
This will require you to use the string value of the measure in your calc formula, so the substitution is used.
Formula=Round(((MeasureUploadedGB + MeasureDownloadedGB) * 100 / [color=#FF0000][[/color]MeasureAllowanceGB[color=#FF0000]][/color],2)
I assure you he has right (as usual) and it does work.
If you still can't get it to remove the error message, please post your code (at least the codes of the [MeasureUploadedGB], [MeasureDownloadedGB] and [MeasureAllowanceGB] measures).
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5406
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Calc: Division by 0 Error in Skin

Post by eclectic-tech »

balala wrote:I don't think so. Have you took into account eclectic-tech's suggestion (I marked red the most important part of his reply):

I assure you he has right (as usual) and it does work.
If you still can't get it to remove the error message, please post your code (at least the codes of the [MeasureUploadedGB], [MeasureDownloadedGB] and [MeasureAllowanceGB] measures).
Thanks for adding the needed for RegExpSubstitution=1 and ^0$ to the substitution method I suggested. :17oops
That method should work now, so seeing the code is the only way to find out why it is not working for them. :17nodding
DavidFw1960
Posts: 42
Joined: December 27th, 2016, 1:32 am

Re: Calc: Division by 0 Error in Skin

Post by DavidFw1960 »

Code: Select all

[MeasureABB]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=60
Url=file://#@#Scripts\ABB-Usage.txt
RegExp="(?siU)<usage>.+<down1>(\d+)<.+<up1>(\d+)<.+<allowance1_mb>(\d+)<.+<left1>(\d+)<.+lastupdated>(.+)<.+<rollover>(\d+)<.rollover>.+usage>"

[MeasureDownloaded]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureABB]
StringIndex=1

[MeasureUploaded]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureABB]
StringIndex=2

[MeasureAllowance]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureABB]
StringIndex=3
RegExpSubstitute=1
Substitute="^0$":"0.000001"

[MeasureTotalUsed]
Measure=Calc
Formula=MeasureDownloaded + MeasureUploaded
DynamicVariables=1

[PercentUsedData]
Measure=Calc
Formula=Round(((MeasureTotalUsed / [MeasureAllowance]) / 10000 ),2)
DynamicVariables=1
Now it shows a Calc: Extra Operation error in the [PercentUsedData] measure
DavidFw1960
Posts: 42
Joined: December 27th, 2016, 1:32 am

Re: Calc: Division by 0 Error in Skin

Post by DavidFw1960 »

Code: Select all

[MeasureAllowance]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureABB]
StringIndex=3

[MeasureAllowanceNonZero]
Measure=Calc
Formula=MeasureAllowance
RegExpSubstitute=1
Substitute="^0$":"0.000001"

[PercentUsedData]
Measure=Calc
;For plans that are NOT unlimited, allow proper calculation of % remaining by removing below comment
Formula=Round(((MeasureTotalUsed / [MeasureAllowanceNonZero]) / 10000 ),2)
;For UNLIMITED plans, use a NOMINAL 1000gb limit by removing below comment
;Formula=Round((MeasureTotalUsed / 10000000000 ),2)
DynamicVariables=1
This worked though.....

As I said previously, the string is being read from a text file (Originally I was converting to GB but removed that to use the raw values)..... It's downloaded directly from my ISP in xml and is never zero.
Maybe the file is blank when it's first trying to execute the skin? (and therefore zero and divide by zero)?

Can I put a delay in so it waits for the file to be updated before showing the skin?