by default, a Calc measure will return 0 if measure used by the Calc measure doesn't give a number value. But it makes me a problem and i want that, if the parent measure doesn't return a number value (is empty), that the calc doesn't return the 0 but to be empty or to use sth like "--" and when the parent measure have "0" as a number value, then the calc should have return it.
So, a simple Substitution like "0":"--" won't help.
In many cases 0 means "nothing", while as for temperature, it's a real value.
It is currently April 26th, 2024, 3:41 am
Calc measure 0 (zero), avoid
-
- Posts: 442
- Joined: July 30th, 2014, 10:30 am
Calc measure 0 (zero), avoid
Last edited by pul53dr1v3r on December 4th, 2019, 2:52 pm, edited 1 time in total.
-
- Posts: 908
- Joined: December 30th, 2015, 9:47 am
Re: Calc measure 0 (zero), avoid
This may be an unsmart solution....But anyway, how about show result simply via variable? Like this;
Probably somone here will provide more smart solution.
Also, If I am misunderstanding your aim, sorry.
Code: Select all
[Rainmeter]
Update=1000
BackgroundMode=2
SolidColor=192,192,192,192
[Variables]
ShowString=""
[ParentMeasure]
Measure=String
;String=""
;String="n/a"
String="0"
;String="18"
IfMatchMode=1
IfMatch=[0-9]
IfMatchAction=[!SetVariable ShowString [ChildCalc:0]]
IfNotMatchAction=[!SetVariable ShowString [ParentMeasure]]
DynamicVariables=1
[ChildCalc]
Measure=Calc
Formula=([ParentMeasure]-32)*5/9
DynamicVariables=1
[meterParentMeasure]
Meter=String
MeasureName=ParentMeasure
X=5
Y=5
Text=Original: %1
[meterChildCalc]
Meter=String
MeasureName=ChildCalc
X=5
Y=20
Text=Child: %1
[meterShowString]
Meter=String
X=5
Y=35
Text=String: #ShowString#
DynamicVariables=1
Also, If I am misunderstanding your aim, sorry.
You do not have the required permissions to view the files attached to this post.
-
- Developer
- Posts: 22630
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Calc measure 0 (zero), avoid
Pul53dr1v3r wrote: ↑November 29th, 2019, 11:05 pm by default, a Calc measure will return 0 if measure used by the Calc measure doesn't give a number value. But it makes me a problem and i want that, if the parent measure doesn't return a number value (is empty), that the calc doesn't return the 0 but to be empty or to use sth like "--" and when the parent measure have "0" as a number value, then the calc should have return it.
So, a simple Substitution like "0":"--" won't help.
In many cases 0 means "nothing", while as for temperature, it's a real value.
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Variables]
[MeasureString]
Measure=String
;String=""
;String=0
String=47
IfMatch=^$
IfMatchAction=[!SetOption MeasureCalc Substitute """0":"--"""]
IfNotMatchAction=[!SetOption MeasureCalc Substitute ""]
[MeasureCalc]
Measure=Calc
Formula=MeasureString
[MeterCalc]
Meter=String
MeasureName=MeasureCalc
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Unlike IfCondition, IfMatch must be on the measure in question, as it uses the value of the measure it resides on to match "with".
You need to use """magic quotes""" on the parameter to set the Substitute, as it begins and ends with a "quote".
Again, NOTHING (no measure) can have an empty number value. That is just not possible.
I don't think I would test FOR a number, as any IfMatch you use will need to be quite complicated to handle possible negative numbers and fractions. It's doable, but I think it is better to test for FOR the empty string, which is simple and unambiguous.
If you really need to test for "N/A" or "ERROR" or some other string that for your purposes has a meaning of "none", then use more conditions on the IfMatch to explicitly test for those. Just saying "is there a number anywhere in the string?" is not particularly useful in my view. It might work in this particular case, but it's lazy logic...
Code: Select all
[MeasureString]
Measure=String
;String=""
;String=0
;String=n/a
;String=Error
String=47
IfMatch=(?i)^$|N/A|ERROR
IfMatchAction=[!SetOption MeasureCalc Substitute """0":"--"""]
IfNotMatchAction=[!SetOption MeasureCalc Substitute ""]
-
- Posts: 908
- Joined: December 30th, 2015, 9:47 am
Re: Calc measure 0 (zero), avoid
As always, jsmorley is smart and powerful (far more than me ).
-
- Developer
- Posts: 22630
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Calc measure 0 (zero), avoid
Meh, you were on the right track. I just tweaked it a bit.
-
- Posts: 442
- Joined: July 30th, 2014, 10:30 am
Re: Calc measure 0 (zero), avoid
[/quote]
i don't agree. Any solution that works is smart. Isn't even a workable Nokia 3310 better than a Galay S10 that's went off. But your solution is much more of it.
Thank you! And you'll probably agree that it have a bit more meters than it should, but it doesn't hurt anyway.
This would be my approach (after i turned my brain on and saw your method):
Your approach will work if there is no any additional calculation in the formula of the Calc measure. But if there is, it will show the calculated value, no matter if the parent measure have any number value or not.
You didn't think of it.
so in the situation above there will be a number valul (5 in this case) even if the parent measure doesn't have any numebr.
It would be a great approach if the calculations could be "ignored" when the parent measure is "empty" (of number values).
Hi mak.
i don't agree. Any solution that works is smart. Isn't even a workable Nokia 3310 better than a Galay S10 that's went off. But your solution is much more of it.
Thank you! And you'll probably agree that it have a bit more meters than it should, but it doesn't hurt anyway.
This would be my approach (after i turned my brain on and saw your method):
Code: Select all
[Variables]
Unit=0
[ParentMeasure]
...
IfMatch=^$
IfMatchAction=[!SetOption "meterShowString" "Text" "--"]
IfNotMatchAction=[!SetOption "meterShowString" "Text" "%1"]
[ChildCalc]
Measure=Calc
Formula=((#Unit#=0)?([ParentMeasure]-32)*5/9 : [ParentMeasure])
DynamicVariables=1
[meterShowString]
Meter=String
MeasureName=ChildCalc
X=5
Y=35
DynamicVariables=1
oh, thank you for all that explanations.
Your approach will work if there is no any additional calculation in the formula of the Calc measure. But if there is, it will show the calculated value, no matter if the parent measure have any number value or not.
You didn't think of it.
Code: Select all
[MeasureCalc]
Measure=Calc
Formula=(MeasureString+5)
It would be a great approach if the calculations could be "ignored" when the parent measure is "empty" (of number values).
-
- Posts: 908
- Joined: December 30th, 2015, 9:47 am
Re: Calc measure 0 (zero), avoid
Hi Pul53dr1v3r
All approaches in this forum are always useful/helpful for me. And I know there would be many approaches for one single aim.
Anyway, my IfMatch= expression in above post was really "loose". If input string includes both digits and non-digit characters like "Tokyo2020", this skin did not work as intended.
This, possibly, should be IfMatch=^\d+\.?\d*$ instead of too simple IfMatch=[0-9]. This RegExp works for digits having decimals, I expect.
Honestly, the world of regular expression is too deep for me. I can't see into its depth, at least so far.
Further, although this doesn't affect the result, when the input string is not only digits, "Calc *** is unknown" error occurs in [ChildCalc] measure.
To avoid this error, [ChildCalc] measure should be disabled at startup and [!EnableMeasure ChildCalc] only when above IfMatch is true.
All approaches in this forum are always useful/helpful for me. And I know there would be many approaches for one single aim.
Anyway, my IfMatch= expression in above post was really "loose". If input string includes both digits and non-digit characters like "Tokyo2020", this skin did not work as intended.
This, possibly, should be IfMatch=^\d+\.?\d*$ instead of too simple IfMatch=[0-9]. This RegExp works for digits having decimals, I expect.
Honestly, the world of regular expression is too deep for me. I can't see into its depth, at least so far.
Further, although this doesn't affect the result, when the input string is not only digits, "Calc *** is unknown" error occurs in [ChildCalc] measure.
To avoid this error, [ChildCalc] measure should be disabled at startup and [!EnableMeasure ChildCalc] only when above IfMatch is true.
Last edited by mak_kawa on December 1st, 2019, 10:48 am, edited 1 time in total.
-
- Posts: 826
- Joined: November 20th, 2012, 11:58 pm
Re: Calc measure 0 (zero), avoid
I usually use a FinishAction in the parent measure if it is a webparser measure.
-
- Posts: 908
- Joined: December 30th, 2015, 9:47 am
Re: Calc measure 0 (zero), avoid
Hi FreeRaider
Yes, FinishAction= option is very useful in some situation. I am often using it with FileView Plugin also.
As I have looked into Rainmeter documents, RunCommand Plugin also has this option...I didn't explicitly realize.
Yes, FinishAction= option is very useful in some situation. I am often using it with FileView Plugin also.
As I have looked into Rainmeter documents, RunCommand Plugin also has this option...I didn't explicitly realize.
-
- Posts: 442
- Joined: July 30th, 2014, 10:30 am
Re: Calc measure 0 (zero), avoid
i agree. Even not working examples can help sometimes to find a solution.
That way your and Morley's helped me to start my, sometimes kind of rusty brain since from time to time i'm slow on the draw.
hi Raider. Yes, i'm also using them in any of the parent webparser measures, to enable and update the childs and meters on any update cycle.FreeRaider wrote: ↑December 1st, 2019, 9:44 am I usually use a FinishAction in the parent measure if it is a webparser measure.