It is currently May 7th, 2024, 5:14 am

Convert Input Text to Upper Case

Get help with creating, editing & fixing problems with skins
User avatar
maxthegold
Posts: 19
Joined: February 11th, 2012, 6:18 am
Location: Kiama, NSW, Australia

Convert Input Text to Upper Case

Post by maxthegold »

I was wondering if anyone can help me with an upper case problem. I have a skin that obtains text from the user and writes its to a .inc file. This is then used to look up a web page. Unfortunately the web page is case sensitive so I need to make sure these values are upper case. How can I convert this data to upper case, either at input or afterwards when I read them back.
The input code is,

Code: Select all

[MsInputCurrency]
Measure=PLUGIN
Plugin=InputText.dll
X=#MidPoint#
W=30
H=20
FontFace=Trebuchet MS
FontSize=10
FontColor=128,192,255,160
StringStyle=BOLD
SolidColor=32,32,32
UpdateDivider=-1
FocusDismiss=1
Command1=!Execute [!WriteKeyValue Variables CurrencyS "$UserInput$" "#SKINSPATH#CurrencyExch\CurVar.inc"][!Refresh #CURRENTCONFIG#] Y=45 DefaultValue="#CurrencyS#"
Command2=!Execute [!WriteKeyValue Variables Currency1 "$UserInput$" "#SKINSPATH#CurrencyExch\CurVar.inc"][!Refresh #CURRENTCONFIG#] Y=60 DefaultValue="#Currency1#"
Command3=!Execute [!WriteKeyValue Variables Currency2 "$UserInput$" "#SKINSPATH#CurrencyExch\CurVar.inc"][!Refresh #CURRENTCONFIG#] Y=75 DefaultValue="#Currency2#"
Command4=!Execute [!WriteKeyValue Variables Currency3 "$UserInput$" "#SKINSPATH#CurrencyExch\CurVar.inc"][!Refresh #CURRENTCONFIG#] Y=90 DefaultValue="#Currency3#"

[CurrencySText]
Meter=STRING
MeterStyle=StyleText
Text="#CurrencyS#"
LeftMouseUpAction=!CommandMeasure "MsInputCurrency" "ExecuteBatch 1"
TooltipTitle="Base Currency"
TooltipText=Click to type the three letter code of the base currrency to use. This is the currency that you want the other currencies converted to or from.  
User avatar
Brian
Developer
Posts: 2689
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Convert Input Text to Upper Case

Post by Brian »

Check out StringCase.

In your meter [CurrencySText], add this line: StringCase=UPPER.

Edit: Misread your post, so the above wont work.... :oops:

Anyway, what you want can still be done, but inside a Lua script.

-Brian
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Convert Input Text to Upper Case

Post by poiru »

Here is an example using Lua.

In the skin:

Code: Select all

[mScript]
Measure=Script
ScriptFile=WriteKeyValueUpper.lua
UpdateDivider=-1

...

LeftMouseUpAction=!CommandMeasure mScript """WriteKeyValueUpper('Variables', 'Test', 'hello world', [[#CURRENTPATH##CURRENTFILE#]])"""
WriteKeyValueUpper.lua file:

Code: Select all

function WriteKeyValueUpper(section, name, value, file)
	SKIN:Bang('!WriteKeyValue ' .. section .. ' ' .. name .. ' "' .. string.upper(value) .. '" "' .. file .. '"')
end
User avatar
maxthegold
Posts: 19
Joined: February 11th, 2012, 6:18 am
Location: Kiama, NSW, Australia

Re: Convert Input Text to Upper Case

Post by maxthegold »

Thanks for that. I see how the conversion and the writing works. What I am still unclear about is how to work the $UserInput$ bit into the code. :confused:
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Convert Input Text to Upper Case

Post by jsmorley »

maxthegold wrote:Thanks for that. I see how the conversion and the writing works. What I am still unclear about is how to work the $UserInput$ bit into the code. :confused:
Don't use this exactly, as it is just a rough example sorta based on your current skin, but this is the approach we are suggesting:

Skin File:

Code: Select all

[Variables]
CurrencyS=JSM

[MeasureScript]
Measure=Script
ScriptFile=WriteKeyValueUpper.lua
UpdateDivider=-1

[MeasureInput]
Measure=PLUGIN
Plugin=InputText.dll
X=0
W=30
H=20
FontFace=Trebuchet MS
FontSize=10
FontColor=128,192,255,160
StringStyle=BOLD
SolidColor=32,32,32
AntiAlias=1
UpdateDivider=-1
FocusDismiss=1
Command1=!Execute [!CommandMeasure MeasureScript """WriteKeyValueUpper('Variables', 'CurrencyS', '$UserInput$', [[#CURRENTPATH##CURRENTFILE#]])"""][!Refresh #CURRENTCONFIG#] Y=45 DefaultValue="#CurrencyS#"

[MeterInput]
Meter=STRING
X=0
Y=45
FontFace=Trebuchet MS
FontSize=10
FontColor=128,192,255,160
StringStyle=BOLD
SolidColor=32,32,32
AntiAlias=1
Text="#CurrencyS#"
LeftMouseUpAction=!CommandMeasure "MeasureInput" "ExecuteBatch 1"
WriteKeyValueUpper.lua:

Code: Select all

function WriteKeyValueUpper(section, name, value, file)

   SKIN:Bang('!WriteKeyValue ' .. section .. ' ' .. name .. ' "' .. string.upper(value) .. '" "' .. file .. '"')
   
end
So [MeterInput] kicks off [MeasureInput] when you left click it. [MeasureInput] will get the user's input text, and call [MeasureScript], the Lua. It will pass the function in Lua "Variables", "CurrencyS", $UserInput$, and the path and name of the current skin file. The Lua script WriteKeyValueUpper.lua will convert the string to upper case, and use !WriteKeyValue to physically change the variable CurrencyS under [Variables] in the current file. Then the [MeasureInput] "batch" will refresh the skin and you are all set to use the spanking new upper case variable in your WebParser measure to the currency site.

Two notes:

The """ quoting around the call to the Lua script is to ensure that the entire string is sent by Rainmeter to the script without Rainmeter trying to interpret any embedded quotes or white space in the string.

The [[ ]] double brackets around [[#CURRENTPATH##CURRENTFILE#]] is using a built-in Lua feature that uses what is inside the [[ ]] as a literal string, so that the "\" characters in a path are not treated as "escapes" by the Lua code.


Let us know if anything about this isn't clear.
User avatar
maxthegold
Posts: 19
Joined: February 11th, 2012, 6:18 am
Location: Kiama, NSW, Australia

Re: Convert Input Text to Upper Case

Post by maxthegold »

You sir are a gentleman and a scholar.

That works perfectly. Thanks very much.

:D
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Convert Input Text to Upper Case

Post by jsmorley »

Glad to help.