It is currently April 20th, 2024, 1:14 am

Simple question, I think

Get help with creating, editing & fixing problems with skins
User avatar
JamX
Posts: 207
Joined: October 4th, 2019, 2:46 pm

Simple question, I think

Post by JamX »

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?
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Simple question, I think

Post by balala »

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)
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Simple question, I think

Post by jsmorley »

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.
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Simple question, I think

Post by balala »

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.
User avatar
JamX
Posts: 207
Joined: October 4th, 2019, 2:46 pm

Re: Simple question, I think

Post by JamX »

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. :thumbup:
User avatar
JamX
Posts: 207
Joined: October 4th, 2019, 2:46 pm

Re: Simple question, I think

Post by JamX »

Just for my curiosity.

What would be the substitute if you want the negative sign removed from the initial number?
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Simple question, I think

Post by balala »

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?
User avatar
JamX
Posts: 207
Joined: October 4th, 2019, 2:46 pm

Re: Simple question, I think

Post by JamX »

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. :thumbup: