It is currently May 1st, 2024, 5:25 am

How can I use a string in a formula?

Get help with creating, editing & fixing problems with skins
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

How can I use a string in a formula?

Post by Virginityrocks »

I want to ask the skin, does a string contain any letters? No? Then set the variable to 0. If it does, set the variable to 1. Easy enough to do this with just numbers, but I need to know if a particular measure if giving me words or is giving me a dummy string.

Code: Select all

Measure=Calc
Formula=MeasureCondiments  = "" ? 0 : 1
IfEqualValue=0
IfEqualAction=[!SetVariable hotdog 0][!Redraw]
IfAboveValue=0
IfAboveAction=[!SetVariable hotdog 1][!Redraw]
Also, is this possible? With its then and else being strings, not numbers? (This part is pure curiosity)

Code: Select all

Measure=Calc
Formula=MeasureCondiments = "" ? "ketchup" : "mustard"
IfEqualValue="ketchup"
IfEqualAction=[!SetVariable hotdog 1][!Redraw]
IfAboveValue="mustard"
IfAboveAction=[!SetVariable hotdog 2][!Redraw]
Last edited by Virginityrocks on May 19th, 2012, 4:36 pm, edited 1 time in total.
Droptop Four
Dropdown menu bar & app launcher for Windows & Rainmeter
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How can I use a string in a formula? "

Post by jsmorley »

No, a Calc measure can only use numbers in the formula and / or IfActions.
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

Re: How can I use a string in a formula? "

Post by Virginityrocks »

Straight up? Is there no way to ask if a string has a value, or not? Like a true or false type-deal?

I have a plugin that stores 20 strings in a table. It stores 20 strings even if 10 of those strings are blank, but if you were to ask the plugin how many strings it has, it will always say 20.
Last edited by Virginityrocks on May 19th, 2012, 4:41 pm, edited 1 time in total.
Droptop Four
Dropdown menu bar & app launcher for Windows & Rainmeter
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How can I use a string in a formula? "

Post by jsmorley »

Virginityrocks wrote:Straight up? Is there no way to ask if a string has a value, or not? Like a true or false type-deal?
Nope. You would need to jump out to Lua to do string comparisons, unless you use a Substitute on a measure returning a string to turn string values into numbers.
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

Re: How can I use a string in a formula? "

Post by Virginityrocks »

I was learning lua yesterday trying to figure out how to do that, but it's pretty complicated. And I can't seem to get anything to work right.

Also, how can I use substitutes to get the desired result?
Droptop Four
Dropdown menu bar & app launcher for Windows & Rainmeter
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: How can I use a string in a formula? "

Post by poiru »

This should do the trick:

Code: Select all

[MeasureCondiments]
...
Substitute="^.+$":"1","^$":"0"
RegExpSubstitute=1

[MeasureCheck]
Measure=Calc
Formula=[MeasureCondiments]
IfEqualValue=0
IfEqualAction=...
IfAboveValue=0
IfAboveAction=...
DynamicVariables=1
(If you need the actual value of MeasureCondiments, duplicate it.)
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

Re: How can I use a string in a formula?

Post by Virginityrocks »

OOOOkay. I think I understand now. It's kind of strange that, even though the number is still part of a string, it's still recognized as a number. I think programming Rainmeter to accept strings as values for formulas would be a good addition to future versions of the program.
Droptop Four
Dropdown menu bar & app launcher for Windows & Rainmeter
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

Re: How can I use a string in a formula?

Post by Virginityrocks »

Alright, so now that I have that sorted out, it causes a new problem.

Since I've substituted all of my blank strings with 1 (Substitute="":"1") in order to calculate the total number of blank strings by adding each 1 together, now each blank string is shown as 1. For example, my output might be:

4walled
Facebook
Google+
1
1
1
1
1

I want to remove the 1s from the string immediately after the value is calculated, and before the string is written.

I have tried using !SetOption Strings Text "", but that doesn't do anything.
I have also tried setting it to something else, but that doesn't solve the problem, it just changes 1 to some other visible entity.

Is there a character that I can use in !SetOption Strings Text "" that rainmeter will not display if I place it in the editor? Like a double slash, or some other combination of characters that do not display if written?
Droptop Four
Dropdown menu bar & app launcher for Windows & Rainmeter
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: How can I use a string in a formula?

Post by poiru »

Like I said, duplicate the measures if you need the actual value.
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

Re: How can I use a string in a formula?

Post by Virginityrocks »

I saw that you wrote that but I don't understand what you mean by duplicate.

Also, I just want to make a note that RegExpSubstitute causes Rainmeter to crash when I place it in the field you've written. I'm not sure if that is necessary for this function.
Last edited by Virginityrocks on May 20th, 2012, 5:21 pm, edited 1 time in total.
Droptop Four
Dropdown menu bar & app launcher for Windows & Rainmeter