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?
It is currently April 26th, 2024, 1:48 pm
Calc: Division by 0 Error in Skin
-
- Posts: 42
- Joined: December 27th, 2016, 1:32 am
-
- Rainmeter Sage
- Posts: 5406
- Joined: April 12th, 2012, 9:40 pm
- Location: Cedar Point, Ohio, USA
Re: Calc: Division by 0 Error in Skin
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)
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)
:: My DA Gallery :: Rainmeter DA Gallery :: Rainmeter Workshops :: Rainmeter Documentation :: BBCode Guide ::
-
- Posts: 42
- Joined: December 27th, 2016, 1:32 am
Re: Calc: Division by 0 Error in Skin
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.
That got rid of the error. Thanks.
I was originally thinking to wait for it to be non-zero but this works too.
-
- Posts: 42
- Joined: December 27th, 2016, 1:32 am
Re: Calc: Division by 0 Error in Skin
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.
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.
-
- Rainmeter Sage
- Posts: 16172
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Calc: Division by 0 Error in Skin
I think a better solution would be to add instead of a Substitute="0":"0.000001" option, the following two options:eclectic-tech wrote:2.) Add Substitute="0":"0.000001" to [MeasureAllowanceGB] section.
Code: Select all
RegExpSubstitute=1
Substitute="^0$":"0.000001"
-
- Posts: 42
- Joined: December 27th, 2016, 1:32 am
Re: Calc: Division by 0 Error in Skin
Tried that. Still divide by zero error.
First solution works.
Thanks anyway.
First solution works.
Thanks anyway.
-
- Rainmeter Sage
- Posts: 16172
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Calc: Division by 0 Error in Skin
I don't think so. Have you took into account eclectic-tech's suggestion (I marked red the most important part of his reply):DavidFw1960 wrote:Tried that. Still divide by zero error.
First solution works.
Thanks anyway.
I assure you he has right (as usual) and it does work.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)
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).
-
- Rainmeter Sage
- Posts: 5406
- Joined: April 12th, 2012, 9:40 pm
- Location: Cedar Point, Ohio, USA
Re: Calc: Division by 0 Error in Skin
Thanks for adding the needed for RegExpSubstitution=1 and ^0$ to the substitution method I suggested.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).
That method should work now, so seeing the code is the only way to find out why it is not working for them.
:: My DA Gallery :: Rainmeter DA Gallery :: Rainmeter Workshops :: Rainmeter Documentation :: BBCode Guide ::
-
- Posts: 42
- Joined: December 27th, 2016, 1:32 am
Re: Calc: Division by 0 Error in Skin
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
-
- Posts: 42
- Joined: December 27th, 2016, 1:32 am
Re: Calc: Division by 0 Error in Skin
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
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?