List Items in a List in Search Tab

Discuss and share scripts and script files...
highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: List Items in a List in Search Tab

Post by highend »

Code: Select all

 $Test = "Test";
 $Test2 = "Test2";
 $Combine = Eval($Test1$Test2);
 Text $Combine;
On my system it outputs:
$Test1Test2


You didn't assign $Test1 so what do you expect?

Code: Select all

 $Test1 = "Test1";
 $Test2 = "Test2";
 $Combine = Eval($Test1$Test2);
 Text $Combine;
This one outputs Test1Test2...
One of my scripts helped you out? Please donate via Paypal

Enternal
Posts: 1174
Joined: 10 Jan 2012 18:26

Re: List Items in a List in Search Tab

Post by Enternal »

highend wrote:

Code: Select all

 $Test = "Test";
 $Test2 = "Test2";
 $Combine = Eval($Test1$Test2);
 Text $Combine;
On my system it outputs:
$Test1Test2


You didn't assign $Test1 so what do you expect?

Code: Select all

 $Test1 = "Test1";
 $Test2 = "Test2";
 $Combine = Eval($Test1$Test2);
 Text $Combine;
This one outputs Test1Test2...
Hahaha you caught me doing something stupid. I wrote $Test but in my mind, it was $Test1. Thank you.

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: List Items in a List in Search Tab

Post by Marco »

Mmh, your output should be $Test1Test2, and that's correct. You didn't define any variable $Test1! ;)
Here's what you probably meant (and what works as you'd expect)

Code: Select all

 $Test1 = "It's gonna be legen—wait for i";
 $Test2 = "t—dary!<crlf 2><tab 2>Barnabus 'Barney' Stinson (born 1976)";
 $Combine = Eval($Test1$Test2);
 Text $Combine;
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

Enternal
Posts: 1174
Joined: 10 Jan 2012 18:26

Re: List Items in a List in Search Tab

Post by Enternal »

Marco wrote:Mmh, your output should be $Test1Test2, and that's correct. You didn't define any variable $Test1! ;)
Here's what you probably meant (and what works as you'd expect)

Code: Select all

 $Test1 = "It's gonna be legen—wait for i";
 $Test2 = "t—dary!<crlf 2><tab 2>Barnabus 'Barney' Stinson (born 1976)";
 $Combine = Eval($Test1$Test2);
 Text $Combine;
Yep. It completely works. :oops:
Tricks of the mind. On another note, on my system, your script was outputting this:
It's gonna be legen—wait for it—dary!

Barnabus 'Barney' Stinson (born 1976)
Yes. Those odd symbols showed up. Looks like Don is going to have another fun time with encoding issues. This time the cause is pretty much just the encoding of the script file. If the file is in ANSI, your script comes out as expected. If it's in UTF-8, then we have a problem lol. Now I'm starting to feel bad, if you notice, lately I have been submitting quite a bit of bugs... now there's a new one...

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: List Items in a List in Search Tab

Post by Marco »

An utf8 xys doesn't even load properly on my system :bug:
Attachments
script.xys
(174 Bytes) Downloaded 152 times
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

Enternal
Posts: 1174
Joined: 10 Jan 2012 18:26

Re: List Items in a List in Search Tab

Post by Enternal »

Marco wrote:An utf8 xys doesn't even load properly on my system :bug:
Yeah. Encoding issues is still one mean problem. If XYplorer was natively Unicode, it will probably be a lot better but since it's still isn't, we have all these odd issues. My code page is currently set to something else that is primarily Unicode so I can load UTF-8 files but it just won't completely process it correctly. You probably have it on a different code page that's likely ANSI so it won't even load the script file at all. Don's going to have fun when he comes back lol.

That reminds me of another issue. ::Snippet have issues when the script have tabs in them.

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: List Items in a List in Search Tab

Post by Marco »

Ah wait wait - The em dash I put there is the cause. In fact if you copy the script from the page in the Try Script window everything works smoothly.
And if you save the xys as utf16le it'll work smoothly as well.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

Enternal
Posts: 1174
Joined: 10 Jan 2012 18:26

Re: List Items in a List in Search Tab

Post by Enternal »

Marco wrote:Ah wait wait - The em dash I put there is the cause. In fact if you copy the script from the page in the Try Script window everything works smoothly.
And if you save the xys as utf16le it'll work smoothly as well.
Ah I see. That em dash does not seem to be in UTF-8 so that's probably why. So it's not a bug at all.
Anyways, another update to my script. After I learned more about variables scope, the script now only uses Perms when needed. The rest of the time it either uses local or global variables. Also, I have shorten the variable names and use a naming method similar to what TheQWERTY was suggesting. Thank you everyone. I'm going to see what else I'm going to do before actually releasing it. Any suggestions?

Code: Select all

"_Initialize"
	Perm $P_SStore1;
	Perm $P_SStore2;
	Perm $P_SStoreNum;
	If $P_SStoreNum == "" {$P_SStoreNum = 1;}


/* -------- Menu -------- */
	Global $G_SStoreName = Self("base");
	Global $P_SStoreMenu =<<<Menu
"Add to Store #$P_SStoreNum|:newtab"
	Load "$G_SStoreName", "_Add";
"Remove from Store #$P_SStoreNum|:closetab"
	Load "$G_SStoreName", "_Remove";
""
"Edit Store #$P_SStoreNum|:rename"
	Load "$G_SStoreName", "_Edit";
"Show Store #$P_SStoreNum|:grid"
	Load "$G_SStoreName", "_Show";
"Copy Store #$P_SStoreNum to Clip|:clip"
	Load "$G_SStoreName", "_Copy";
""
"Copy Store #$P_SStoreNum to Here|:copyto"
	Load "$G_SStoreName", "_CopyTo";
"Move Store #$P_SStoreNum to Here|:moveto"
	Load "$G_SStoreName", "_MoveTo";
""
"Clear Store #1|:stop"
	Load "$G_SStoreName", "_Clear1";
"Clear Store #2|:stop"
	Load "$G_SStoreName", "_Clear2";
"Clear All Store|:del"
	Load "$G_SStoreName", "_ClearAll";
""
"Activate Store #1|:dp1"
	Load "$G_SStoreName", "_Act1";
"Activate Store #2|:dp2"
	Load "$G_SStoreName", "_Act2";
Menu;




/* -------- Drag n' Drop -------- */
"Selection Store"
	If <get drop |> != "" {
		$localCountItems = GetToken(<get drop |>, "count", "|");
		If $P_SStoreNum == 2 {
			$P_SStore2 = "$P_SStore2"."|".<get drop |>;
			$P_SStore2 = FormatList("$P_SStore2","ned"); }
		Else {
			$P_SStore1 = "$P_SStore1"."|".<get drop |>;
			$P_SStore1 = FormatList("$P_SStore1","ned"); }
		Status "$localCountItems Item(s) Added to Selection Store #$P_SStoreNum.",,"ready"; }
	Else {
		Global $P_SStoreMenu;
		Load $P_SStoreMenu,*,s; }




/* -------- Body -------- */
"_Add"
	End ("<selitems>"==""),"Nothing Is Selected!";
	$localCountItems = Get("CountSelected");
	If $P_SStoreNum == 2 {
		$P_SStore2 = "$P_SStore2"."|".Get("SelectedItemsPathNames","|");
		$P_SStore2 = FormatList("$P_SStore2","ned"); }
	Else {
		$P_SStore1 = "$P_SStore1"."|".Get("SelectedItemsPathNames","|");
		$P_SStore1 = FormatList("$P_SStore1","ned"); }
	Status "$localCountItems Item(s) Added to Selection Store #$P_SStoreNum.",,"ready";

"_Remove"
	End ("<selitems>"==""),"Nothing Is Selected!";
	$localCountItems = Get("CountSelected");
	Global $P_SStore1Remove = Get("SelectedItemsPathNames","|");
	If $P_SStoreNum == 2 {
		ForEach($Item,$P_SStore1Remove,"|") {
			$P_SStore2 = Replace($P_SStore2,$Item,,1); }
		$P_SStore2 = FormatList("$P_SStore2","ned"); }
	Else {
		ForEach($Item,$P_SStore1Remove,"|") {
			$P_SStore1 = Replace($P_SStore1,$Item,,1); }
		$P_SStore1 = FormatList("$P_SStore1","ned"); }
	Status "$localCountItems Item(s) Removed from Selection Store #$P_SStoreNum.",,"alert";

"_Edit"
	If $P_SStoreNum == 2 {
		If $P_SStore2 > 0 {
			$localContents2 = Replace($P_SStore2,"|","<crlf>");
			$P_SStore2 = Input("Edit Selection Store #2",,$localContents2,m,,750,500);
			$P_SStore2 = Replace($P_SStore2,"<crlf>","|");
			$P_SStore2 = FormatList("$P_SStore2","ned"); } }
	Else {
		If $P_SStore1 > 0 {
			$Contents = Replace($P_SStore1,"|","<crlf>");
			$P_SStore1 = Input("Edit Selection Store #1",,$Contents,m,,750,500);
			$P_SStore1 = Replace($P_SStore1,"<crlf>","|");
			$P_SStore1 = FormatList("$P_SStore1","ned"); } }
	If $P_SStore1 == "" {Status "No Item(s) in Selection Store #$P_SStoreNum.",,"alert";}

"_Show"
	If $P_SStoreNum == 2 {
		If $P_SStore2 > 0 {
			Tag SelectionStoreItems2,$P_SStore2,1;
			Goto "*?Tags:SelectionStoreItems2 /r";
			Tab(Rename, "Selection Store #$P_SStoreNum"); } }
	Else {
		If $P_SStore1 > 0 {
			Tag SelectionStoreItems1,$P_SStore1,1;
			Goto "*?Tags:SelectionStoreItems1 /r";
			Tab(Rename, "Selection Store #$P_SStoreNum"); } }
	If $P_SStore1 == "" {Status "No Item(s) in Selection Store #$P_SStoreNum.",,"alert";}

"_Copy"
	If $P_SStoreNum == 2 {
		If $P_SStore2 > 0 {
			Copy $P_SStore2;
			Status "Copied Selection Store #$P_SStoreNum Item(s) to Windows Clipboard.",,"alert"; } }
	Else {
		If $P_SStore1 > 0 {
			Copy $P_SStore1;
			Status "Copied Selection Store #$P_SStoreNum Item(s) to Windows Clipboard.",,"alert"; } }
	If $P_SStore1 == "" {Status "No Item(s) in Selection Store #$P_SStoreNum.",,"alert";}

"_CopyTo"
	If $P_SStoreNum == 2 {
		If $P_SStore2 > 0 {
			CopyTo <curtab>,$P_SStore2; } }
	Else {
		If $P_SStore1 > 0 {
			CopyTo <curtab>,$P_SStore1; } }
	If $P_SStore1 == "" {Status "No Item(s) in Selection Store #$P_SStoreNum.",,"alert";}

"_MoveTo"
	If $P_SStoreNum == 2 {
		If $P_SStore2 > 0 {
			MoveTo <curtab>,$P_SStore2;
			Tag SelectionStoreItems,$P_SStore2,1,2;
			Unset $P_SStore2; } }
	Else {
		If $P_SStore1 > 0 {
			MoveTo <curtab>,$P_SStore1;
			Tag SelectionStoreItems,$P_SStore1,1,2;
			Unset $P_SStore1; } }
	If $P_SStore1 == "" {Status "No Item(s) in Selection Store #$P_SStoreNum.",,"alert";}

"_Clear1"
	Tag SelectionStoreItems1,$P_SStore1,1,2;
	Unset $P_SStore1;
	Status "Selection Store #1 Cleared!",,"ready";

"_Clear2"
	Tag SelectionStoreItems2,$P_SStore2,1,2;
	Unset $P_SStore2;
	Status "Selection Store #2 Cleared!",,"ready";

"_ClearAll"
	$Clear = Confirm("Are You Sure You Want To Clear All Selection Store?");
	End ($Clear == 0);
	Tag SelectionStoreItems1,$P_SStore1,1,2;
	Tag SelectionStoreItems2,$P_SStore2,1,2;
	Unset $P_SStore1, $P_SStore2, $P_SStoreNum;
	Status "All Selection Store Cleared!",,"ready";
	Msg "All Cleared! Selection Store #1 Will Activate at Next Start.";

"_Act1"
	$P_SStoreNum = 1;
	Status "Selection Store #1 Activated.",,"ready";
	Msg "Selection Store #1 Activated.";

"_Act2"
	$P_SStoreNum = 2;
	Status "Selection Store #2 Activated.",,"ready";
	Msg "Selection Store #2 Activated.";
[/size]

FluxTorpedoe
Posts: 904
Joined: 05 Oct 2011 13:15

Re: List Items in a List in Search Tab

Post by FluxTorpedoe »

Hi'

@Enternal
Your script is becoming bigger'n bigger... That's the trap with XY, we never know when want to stop! ;)

@all
First, thank you all for all your answers! :)

• Regarding Question 1, we have a winner! And it's legen-...... ooops no, it's Filehero! :biggrin:
• How do you keep variables unresolved when nested?
The problem occurs when (re)defining existing variables inside a variable (dynamic menu/script, etc.).
Note: It's problematic when needing to reuse global variables (inside a variable...).
:arrow: The solution is to separate the $ from the var name (as suggested by Filehero here):

Code: Select all

$mscript = $mscript . "  $" . "g_variable = ""different test, hmm?"";<crlf>";
-------------------------

• Regarding the Bonus Question, unfortunately, it's like our last var: unsolved! ;)
• Who knows how to, or would dream of "dynamic" definition of variables?
:arrow: I wasn't clear enough, by dynamic I meant the variable name, not its content. So the purpose wasn't to do
$toto = $foo$bar;
but
$foo$bar = toto;

In the first case, eval() works great indeed, but here my question was the inverse of the last example I'd given in this eval() thread. ;)
Another example would be:

Code: Select all

	$A = "foo";
	$B = "bar";
	$Z = "toto";

  foreach($Var, "A|B|Z", "|") {
    if ("$".$Var == "toto") {
			makecoffee;
		}
  }
-------------------------

• About coding guidelines, it's interesting to see different approaches!
Right now I was going with this:

Code: Select all

$PERMANENT
$GLB_Global
$Local
with FULLCAPS for permanent and a 3 CAP prefix for globals which differentiates their range, e.g.
PRE (predefined at the beginning of the script, i.e. constant),
STG (setting, also a constant, but may be written by user or read from INI, etc.)
DYN (dynamic, e.g. defined by user input), etc.

And for huge script (when I'm serious :wink: ) I use a 1 letter to differentiate the type of var, like
l_ (list)
b_ (binary) , etc.

which gives, e.g.
$PRE_l_AvailSess // List (l) of available sessions, predefined (PRE) i.e. valid for all the script's life
$DYN_b_InpSessLay // Does the session chosen by the user (DYN) have a layout or no (b)?

I copy/paste the "rationale" I use intended to use when I'm not lazy:

Code: Select all

// $Var = local variable; $CAP_Var = global variable; $FULLCAPVAR = permanent variable;
// $*... = any string; $*d_... = delta string (to be added); $*l_... = list; $*a_...= array; $*n_... = number; $*b_... = binary;
// - - -
// e.g. $PRE_Item = Item Name; $PRE_b_Item = Item exists ; $PRE_l_Items = List of items;
|

Post Reply