It is currently September 21st, 2021, 5:12 pm

Can't get correct display value using Abs()?

Help with creating, editing & fixing problems with skins
spaticles
Posts: 5
Joined: July 14th, 2021, 1:25 am

Can't get correct display value using Abs()?

Post by spaticles »

Hey all, I took the Market Prices and My Portfolio Value skins from Mordasius and combined them into one, then added some new functionality, however, I'm having an issue getting a value to display correctly. So, I've got this Total Change column that, based on the values calculated, can produce a negative value, which when concatenated with a "$", displays a "$-200" In an attempt to move that "-", I basically created a new...measure(?) meter(?) (I don't know the correct terminology), that generates the absolute value of the negative number. Then, using an IfBelowAction, I set the Text to "-$[mIndex2_TotalChangeAbs]". Now, the IfAction is definitely working, because it will change the display from "$-200" to "-$200", but something really weird is happening with the value itself. The only value that is $967 is the #TotalInvestment2# from the Portfolio.inc file, but it's only referenced in the .ini in an equation, never by itself, so I don't understand how it's pulling it into this display.

Image

You can see the [mIndex2_TotalChangeAbs] value is correct at 204:
Image

Portfolio.inc:

Code: Select all

Nindex2=C3AI
Symbol2=AI
; Total of your holdings for this stock
Holding2=15
; Below is the investment buy-ins listed one-by-one, to track total $ and % change of account
Investment2Cost1=967.20
;Total of all investment buy-ins for this stock
TotalInvestment2 = #Investment2Cost1#
MyPortfolio.ini: (I think this is all the relevant code. The first 3 are vanilla from the original skin)

Code: Select all

[InfoIndex2]
Measure=WebParser
URL=https://www.cnbc.com/quotes/?symbol=#Symbol2#
UserAgent=#MyUserAgent#
Header=Accept: text/html
Header2=Accept_Encoding: gzip, deflate, br
Header3=Accept_Language: en-US
Header4=Connection: close
Header5=Dnt: 1
Header6=Host: www.CNBC.com
Header7=Referer: https://wwww.google.com
RegExp=#ExpQuote#
StringIndex=1
UpdateRate=#UpdateQuotes#

[mIndex2_PriceNum]
Measure=String
String=[mIndex2_Price]
DynamicVariables=1

[mIndex2_Value]
Measure=Calc
Formula=( [mIndex2_PriceNum:] * #Holding2# )
RegExpSubstitute=1
Substitute="^(\d{1,3})(\d{3})(\d{3})$":"\1,\2,\3","^(\d{1,3})(\d{3})$":"\1,\2"
DynamicVariables=1

[mIndex2_TotalChange]
Measure=Calc
Formula=Round(( mIndex2_Value - #TotalInvestment2#),0)

[mIndex2_TotalChangeAbs]
Measure=Calc
Formula=Abs(mIndex2_TotalChange)


[Label_TotalChange2]
Meter=STRING
MeterStyle=sTextRight
FontColor=#ColorSteady#
x=#Col9XPos#

[TotalChangeColor2]
Measure=Calc
Formula=[mIndex2_TotalChange]
IfAboveValue=0
IfAboveAction=[!SetOption "Label_TotalChange2" "FontColor" "#ColorUp#"] [!SetOption "Label_TotalChangePer2" "FontColor" "#ColorUp#"] [!SetOption "Label_TotalChange2" "Text" $[mIndex2_TotalChange]]
IfEqualValue=0
IfEqualAction=[!SetOption "Label_TotalChange2" "FontColor" "#ColorSteady#"] [!SetOption "Label_TotalChangePer2" "FontColor" "#ColorSteady#"] [!SetOption "Label_TotalChange2" "Text" $[mIndex2_TotalChange]]
IfBelowValue=0
IfBelowAction=[!SetOption "Label_TotalChange2" "FontColor" "#ColorDown#"] [!SetOption "Label_TotalChangePer2" "FontColor" "#ColorDown#"] [!SetOption "Label_TotalChange2" "Text" -$[mIndex2_TotalChangeAbs]]
DynamicVariables=1
I've tried setting Text=[mIndex2_TotalChangeAbs] in [Label_TotalChange2], and then using the IfAction to change it, but that produced the same result. Again, #TotalInvestmen2# is never referenced anywhere in the .ini by itself, so I don't understand how it's being pulled into the display.

Any ideas?
User avatar
balala
Rainmeter Sage
Posts: 13212
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Can't get correct display value using Abs()?

Post by balala »

There is a problem with the [mIndex2_PriceNum] measure:

Code: Select all

[mIndex2_PriceNum]
Measure=String
String=[mIndex2_Price]
DynamicVariables=1
The code doesn't have a measure called [mIndex2_Price], so the [mIndex2_PriceNum] measure doesn't work. Accordingly nor the [mIndex2_Value] measure does and finally [mIndex2_TotalChange] returns always ( 0 - #TotalInvestment2#), which exactly the value we're looking for. Most probably the String option of the [mIndex2_PriceNum] measure should be replaced by String=[InfoIndex2] (my supposition).

Additional comments:
  • Recommend not to use IfActions, which are old. The much versatile IfConditions are recommended instead.
  • spaticles wrote: July 28th, 2021, 1:07 am I've tried setting Text=[mIndex2_TotalChangeAbs] in [Label_TotalChange2], and then using the IfAction to change it, but that produced the same result. Again, #TotalInvestmen2# is never referenced anywhere in the .ini by itself, so I don't understand how it's being pulled into the display.
    Where have you tried adding the IfAction? This option can be used ONLY on measures, never on meters. If you added it to the meter where you've set the Text=[mIndex2_TotalChangeAbs] option, it has been in vain, an IfAction can't and doesn't work there.
spaticles
Posts: 5
Joined: July 14th, 2021, 1:25 am

Re: Can't get correct display value using Abs()?

Post by spaticles »

I'm sorry, I left out the [mIndex2_Price] when I copy/pasted. However, I did follow your suggestion of using the IfCondition instead of IfAction, and it worked! Thanks so much!
User avatar
balala
Rainmeter Sage
Posts: 13212
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Can't get correct display value using Abs()?

Post by balala »

spaticles wrote: July 28th, 2021, 4:19 pm I'm sorry, I left out the [mIndex2_Price] when I copy/pasted. However, I did follow your suggestion of using the IfCondition instead of IfAction, and it worked! Thanks so much!
Simply replacing the IfActions with IfConditions did get the unfunctional measure to work? I'm surprised, but am also glad if it did, :thumbup:
User avatar
Yincognito
Rainmeter Sage
Posts: 4052
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Can't get correct display value using Abs()?

Post by Yincognito »

balala wrote: July 28th, 2021, 6:21 pm Simply replacing the IfActions with IfConditions did get the unfunctional measure to work? I'm surprised, but am also glad if it did, :thumbup:
I think he meant that he followed both your instructions (the mIndex2_Price and turning IfActions into IfConditions) and it worked. He said sorry about the former, so he probably took action to correct that as well.
User avatar
balala
Rainmeter Sage
Posts: 13212
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Can't get correct display value using Abs()?

Post by balala »

Yincognito wrote: July 29th, 2021, 12:53 pm I think he meant that he followed both your instructions (the mIndex2_Price and turning IfActions into IfConditions) and it worked. He said sorry about the former, so he probably took action to correct that as well.
No I think, because he said:
spaticles wrote: July 28th, 2021, 4:19 pm I'm sorry, I left out the [mIndex2_Price] when I copy/pasted. However, I did follow your suggestion of using the IfCondition instead of IfAction, and it worked! Thanks so much!
Which in my interpretation means the [mIndex2_Price] measure was there, just hasn't been posted.
But not very sure...
User avatar
Yincognito
Rainmeter Sage
Posts: 4052
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Can't get correct display value using Abs()?

Post by Yincognito »

balala wrote: July 29th, 2021, 7:16 pm No I think, because he said:

Which in my interpretation means the [mIndex2_Price] measure was there, just hasn't been posted.
But not very sure...
Aah, didn't think of that. Could be, indeed. :???: