It is currently March 29th, 2024, 9:11 am

Calc: Division by 0 Error in Skin

Get help with creating, editing & fixing problems with skins
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5384
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Calc: Division by 0 Error in Skin

Post by eclectic-tech »

DavidFw1960 wrote:

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?
You could disable the [PercentUsedData] measure, then add a FinishAction to the webparser measure that enables that measure and updates it.

Add Disabled=1 to the [PercentUsedData] measure.
Then add FinishAction=[!EnableMeasure PercentUsedData][!UpdateMeasure PercentUsedData] to the [MeasureABB] webparser measure.

This will not try to divide the MeasureTotalUsed until the webparser has finish reading the file and populating the child measures.
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>"
FinishAction=[!EnableMeasure PercentUsedData][!UpdateMeasure PercentUsedData]

[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

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

[PercentUsedData]
Measure=Calc
Formula=Round(((MeasureTotalUsed / MeasureAllowance) / 10000 ),2)
DynamicVariables=1
Disabled=1
Divide by zero error again
HMM!! putting [MeasureAllowance] ie string works with no more errors.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Calc: Division by 0 Error in Skin

Post by balala »

DavidFw1960 wrote:Now it shows a Calc: Extra Operation error in the [PercentUsedData] measure
https://forum.rainmeter.net/viewtopic.php?p=119130#p119130
Solution:
  • Disable the [PercentUsedData] measure (by adding a Disabled=1 option to it).
  • Enable the measure, once the WebParser measure got the appropriate values. This can be done by adding a FinishAction=[!EnableMeasure "PercentUsedData"] option to the [MeasureABB] measure.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Calc: Division by 0 Error in Skin

Post by jsmorley »

Seem to me that there is another pretty straightforward way to avoid all "divide by zero" and "extra operation" errors, [SectionVariabls] and DynamicVariables in this:

Code: Select all

[MeasureABB]
Measure=WebParser
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>"
FinishAction=[!SetOption PercentUsedData Formula "Round(((MeasureTotalUsed / MeasureAllowance) / 10000 ),2)"][!UpdateMeasure *][!UpdateMeter *][!Redraw]

[MeasureDownloaded]
Measure=WebParser
Url=[MeasureABB]
StringIndex=1

[MeasureUploaded]
Measure=WebParser
Url=[MeasureABB]
StringIndex=2

[MeasureAllowance]
Measure=WebParser
Url=[MeasureABB]
StringIndex=3

[MeasureTotalUsed]
Measure=Calc
Formula=MeasureDownloaded + MeasureUploaded

[PercentUsedData]
Measure=Calc
Formula=1
The long and the short of it is that any WebParser measure has an initial value of "" (an empty string) when it is first loaded and before it has gone out to get data the first time. Since WebParser is "threaded" and doesn't cause Rainmeter to wait around for it, on the first skin update, all WebParser measures will always have a value of "".

Any "math" done on this will at best be irrelevant, and at worst create a formula that can't exist in an Einsteinian universe, like dividing something by "", or adding "" to "" and dividing that by 2. One option is to not set those formulas until there is actual data to work with, which will be when the WebParser measure is "finished" for the first time.
DavidFw1960
Posts: 42
Joined: December 27th, 2016, 1:32 am

Re: Calc: Division by 0 Error in Skin

Post by DavidFw1960 »

That's the most elegant solution yet and works great.

Thanks so much and thanks everyone who helped.