Page 1 of 1
SC popupmenu question
Posted: 05 Feb 2024 21:40
by Daniel0312
Code: Select all
$TestString = "Value1<crlf>Value2";
$menu = <<<MENU
::UPPER;copytext recase("$TestString")
MENU;
popupmenu($menu);
The above code works fine as long as there is no <crlf> in the string.
When there is one, it's seen as a break in the code line and interpreted accordingly.
Is there a way around it ?
Re: SC popupmenu question
Posted: 06 Feb 2024 00:15
by jupe
Make sure the variable isn't resolved beforehand. eg.
Code: Select all
$TestString = 'Value1<crlf>Value2';
$menu = <<<MENU
::UPPER;copytext recase("$TestString")
MENU;
popupmenu($menu);
Re: SC popupmenu question
Posted: 06 Feb 2024 08:38
by Daniel0312
Thanks jupe, it works indeed in this case.
The problem is I want to use the clipboard as entry string, and insert this (simplified) code in an existing popupmenu.
Code: Select all
$menu = <<<MENU
Recase
::UPPER;copytext recase("<clipboard>", "upper");
::Invert;copytext recase("<clipboard>", "invert");
MENU;
$return = popupnested($menu, 6:=<crlf>, 7:=";");
I've been trying quite a lot of single and double quotes permutations... no joy.
Single-quoting <clipboard> doesn't seem to be an option.
Any idea (other than creating one sub for each "problem" item) ?
Re: SC popupmenu question
Posted: 06 Feb 2024 09:08
by highend
One way:
Code: Select all
$menu = <<<MENU
Recase
UPPER;recase_upper
Invert;recase_invert
MENU;
$return = popupnested($menu, 6:=<crlf>, 7:=";");
if ($return == "recase_upper") {
copytext recase(<clipboard>, "upper");
} elseif ($return == "recase_invert") {
copytext recase(<clipboard>, "invert");
}
All other entries that don't contain
<crlf> can still be done in the old way
Re: SC popupmenu question
Posted: 06 Feb 2024 09:26
by Daniel0312
It'a a good way, gives me things to think about
It seems the only way is to get the <clipboard> and it's <crlf> out of the menu string.
Thanks highend.
Re: SC popupmenu question
Posted: 07 Feb 2024 02:30
by jupe
There are multiple ways to achieve what you want, here is another one if you are still interested.
Code: Select all
function cb() { return <clp>; }
$menu = <<<MENU
Recase
::UPPER; copytext recase(cb(), "upper");
::Invert;copytext recase(cb(), "invert");
MENU;
$return = popupnested($menu, 6:=<crlf>, 7:=";");
Re: SC popupmenu question
Posted: 07 Feb 2024 07:51
by Daniel0312
I'm always interested in learning new things.
And I really like this one, elegant.
Many thanks jupe.