It is currently April 20th, 2024, 1:14 am
Get help with creating, editing & fixing problems with skins
JamX
Posts: 207 Joined: October 4th, 2019, 2:46 pm
Post
by JamX » January 24th, 2021, 9:19 am
I have a webparser measure which returns a sting which I use in a CALC measure to make it a number.
This work's OK
Code: Select all
[InfoIndex2]
Measure=WebParser
URL=https://www.cnbc.com/quotes/?symbol=#Symbol2#
RegExp=#ExpQuote#
StringIndex=1
RegExpSubstitute=1
Substitute="^(.*) .*$":"\1"
FinishAction=[!EnableMeasureGroup Stock2]
[mIndex2_Price]
Group=Stock2
Disabled=1
Measure=WebParser
Url=[InfoIndex2]
StringIndex=2
Substitute=",":""
[mIndex2.1_Price]
Group=Stock2
Disabled=1
Measure=Calc
Formula=[mIndex2_Price]*1
DynamicVariables=1
[mIndex2_Change]
Group=Stock2
Disabled=1
Measure=WebParser
Url=[InfoIndex2]
StringIndex=3
Substitute="UNCH":"0.00",",":""
[mIndex2.1_Change]
Group=Stock2
Disabled=1
Measure=Calc
Formula=[mIndex2_Change]*1
DynamicVariables=1
The [mIndex2.1_Change] I want to be formatted, when being a positive number, with an "+" added in front of that number.
(Negative values are already proceeding with a "-" sign and the "0.00" should be as it is.)
What REGEXP substitute expression should be used?
balala
Rainmeter Sage
Posts: 16147 Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania
Post
by balala » January 24th, 2021, 12:31 pm
JamX wrote: ↑ January 24th, 2021, 9:19 am
The [mIndex2.1_Change] I want to be formatted, when being a positive number, with an "+" added in front of that number.
(Negative values are already proceeding with a "-" sign and the "0.00" should be as it is.)
Try to add the follwoing options to the [mIndex2.1_Change] measure:
Code: Select all
[mIndex2.1_Change]
...
IfCondition=(#CURRENTSECTION#>0)
IfTrueAction=[!SetOption #CURRENTSECTION# RegExpSubstitute "1"][!UpdateMeasure "#CURRENTSECTION#"]
IfFalseAction=[!SetOption #CURRENTSECTION# RegExpSubstitute "0"][!UpdateMeasure "#CURRENTSECTION#"]
Substitute="^(.*)$":"+\1"
Note that a String meter shows the value of the measure rounded to integer (so if the [mIndex2_Change] gets for instance
1.75 , the meter which shows the value of the updated [mIndex2.1_Change] measure shows
+2 , not
+1.75 )
jsmorley
Developer
Posts: 22629 Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA
Post
by jsmorley » January 24th, 2021, 12:52 pm
Another option might be to use the Prefix option on the String meter displaying the value...
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Variables]
[MeasureValue]
Measure=Calc
Formula=5.68
IfCondition=#CURRENTSECTION# > 0
IfTrueAction=[!SetOption SomeMeter Prefix "+"]
IfFalseAction=[!SetOption SomeMeter Prefix ""]
[SomeMeter]
Meter=String
MeasureName=MeasureValue
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
NumOfDecimals=2
Although I have to say that turning off and on the RegExpSubstitute option like that is quite clever and effective as well.
balala
Rainmeter Sage
Posts: 16147 Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania
Post
by balala » January 24th, 2021, 4:48 pm
jsmorley wrote: ↑ January 24th, 2021, 12:52 pm
Another option might be to use the Prefix option on the String meter displaying the value...
As usually, there are more different solutions this time as well.
JamX
Posts: 207 Joined: October 4th, 2019, 2:46 pm
Post
by JamX » January 24th, 2021, 7:18 pm
balala wrote: ↑ January 24th, 2021, 12:31 pm
Try to add the follwoing options to the [mIndex2.1_Change] measure:
Code: Select all
[mIndex2.1_Change]
...
IfCondition=(#CURRENTSECTION#>0)
IfTrueAction=[!SetOption #CURRENTSECTION# RegExpSubstitute "1"][!UpdateMeasure "#CURRENTSECTION#"]
IfFalseAction=[!SetOption #CURRENTSECTION# RegExpSubstitute "0"][!UpdateMeasure "#CURRENTSECTION#"]
Substitute="^(.*)$":"+\1"
Note that a String meter shows the value of the measure rounded to integer (so if the [mIndex2_Change] gets for instance
1.75 , the meter which shows the value of the updated [mIndex2.1_Change] measure shows
+2 , not
+1.75 )
THX balala, you saved the day, again.
JamX
Posts: 207 Joined: October 4th, 2019, 2:46 pm
Post
by JamX » January 24th, 2021, 7:38 pm
Just for my curiosity.
What would be the substitute if you want the negative sign removed from the initial number?
balala
Rainmeter Sage
Posts: 16147 Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania
Post
by balala » January 24th, 2021, 7:46 pm
JamX wrote: ↑ January 24th, 2021, 7:38 pm
What would be the substitute if you want the negative sign removed from the initial number?
If this is the only thing you want to apply (so nothing related to add the
+ ), you can simply get rid of the IfCondition and apply the following Substitute (no need to set RegExpSubstitute option, as did before):
Substitute="-":"" .
Or adding the + is still required?
JamX
Posts: 207 Joined: October 4th, 2019, 2:46 pm
Post
by JamX » January 24th, 2021, 7:48 pm
jsmorley wrote: ↑ January 24th, 2021, 12:52 pm
Another option might be to use the Prefix option on the String meter displaying the value...
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Variables]
[MeasureValue]
Measure=Calc
Formula=5.68
IfCondition=#CURRENTSECTION# > 0
IfTrueAction=[!SetOption SomeMeter Prefix "+"]
IfFalseAction=[!SetOption SomeMeter Prefix ""]
[SomeMeter]
Meter=String
MeasureName=MeasureValue
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
NumOfDecimals=2
Although I have to say that turning off and on the RegExpSubstitute option like that is quite clever and effective as well.
Thanks jsmorley, this also worked but I implemented balala's code.