[SC] Variable name contain <var>

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
binocular222
Posts: 1424
Joined: 04 Nov 2008 05:35
Location: Win11, Win10, 100% Scaling

[SC] Variable name contain <var>

Post by binocular222 »

This is my general idea but does not works:

Code: Select all

  $Count = 100;
  while($Count <= 104){
    perm $c$Index;
    $c$Index = gettoken(get("MenuCaption", $c$Index, 1), 2, "<tab>");
    Incr $Index;
  }
  echo $c100
How to quickly declare a lot of variables (i.e: $c100, $c101,...,$c1077)?
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: [SC] Variable name contain <var>

Post by bdeshi »

creates permavars $c100,$c101... with values of 100,101...

Code: Select all

  $count = 100;
  while($count <= 104) {
    $var = '$c'.$count;
    //text "variable created: $var";
    //$value = gettoken(get("MenuCaption", $count, 1), 2, "<tab>");
    $value = $count; //dummy values
    load("perm $var = $value;",, s);
    $count++;
  }
Last edited by bdeshi on 16 May 2014 12:27, edited 1 time in total.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

binocular222
Posts: 1424
Joined: 04 Nov 2008 05:35
Location: Win11, Win10, 100% Scaling

Re: [SC] Variable name contain <var>

Post by binocular222 »

Genius! You should have joined this community sooner.
But XY take a significant time to process such as large demand.

Code: Select all

  $count = 100;
  while($count <= 250) {
    $var = '$c'.$count;
    $value = gettoken(get("MenuCaption", $count, 1), 2, "<tab>");
    load("perm $var = $value;",, s);
    $count++;
  }
  echo $c105
@Don: anything unusual with perm?
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: [SC] Variable name contain <var>

Post by bdeshi »

Thanks! I guess I should've discovered XYplorer sooner :biggrin:


BTW, don't know what you're doing, but you probably want to use this instead:

Code: Select all

$value = quote(gettoken(get("MenuCaption", $count, 1), 2, "<tab>"));
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 67114
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: [SC] Variable name contain <var>

Post by admin »

OK, that was a very inspiring thread. :biggrin:

1) I discovered the bug that made it so slow.
2) I added a deference operator that will make this stuff much faster.

BTW, you should quote that value:

Code: Select all

OLD: load("perm $var = $value;",, s);
NEW: load("perm $var = ""$value"";",, s);
But this is now obsolete anyway. This script should look like this in the next version:

Code: Select all

  $count = 100;
  while($count <= 250) {
    $var = '$c'.$count;
    $value = gettoken(get("MenuCaption", $count, 1), 2, "<tab>");
    perm *$var = $value;
    $count++;
  }
  echo $c105;

binocular222
Posts: 1424
Joined: 04 Nov 2008 05:35
Location: Win11, Win10, 100% Scaling

Re: [SC] Variable name contain <var>

Post by binocular222 »

Thanks Don, now I can build a custom menu of frequently-used-XYnative command such as

Code: Select all

"_Initialize"
  if(isset($c101) == 0) {
    $count = 100;
    while($count <= 1077) {
      $Command = '$c'.$count;
      $KBshortcut = gettoken(get("MenuCaption", $count, 1), 2, "<tab>");
      perm *$Command = $KBshortcut;
      $count++;
    }
  };

"Minitree $c489|:minitree" #489
"Toggle Fav Folder $c566|:favs" #566
"Branch view $c311|:flatview" #311
"$HiddenFile|:showhidden" #493; status "Hidden files: " . get("#493", "Show", "Hide") . " | System files: " . get("#494", "Show", "Hide")
"$SystemFile|:showsystem" #494; status "Hidden files: " . get("#493", "Show", "Hide") . " | System files: " . get("#494", "Show", "Hide")
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: [SC] Variable name contain <var>

Post by bdeshi »

XY can construct :shock: dynamic variables :shock: now!!!! :appl:
Don, you are a genie with unlimited wishes! :biggrin:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 67114
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: [SC] Variable name contain <var>

Post by admin »

The line is missing:

Code: Select all

perm *$Command = $KBshortcut;
Don't see a bug after adding the line.

binocular222
Posts: 1424
Joined: 04 Nov 2008 05:35
Location: Win11, Win10, 100% Scaling

Re: [SC] Variable name contain <var>

Post by binocular222 »

Yeah, sorry, I found my mistake.
But why not expand the dereference operator to normal variable, not just global/perm?
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

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

Re: [SC] Variable name contain <var>

Post by FluxTorpedoe »

SammaySarkar wrote:XY can construct :shock: dynamic variables :shock: now!!!! :appl:
Don, you are a genie with unlimited wishes! :biggrin:
Yeahhh! This one is terrific!
And yet another old wish auto-granted… Fertile week indeed! :biggrin:

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: [SC] Variable name contain <var>

Post by bdeshi »

@binocular222, Works with normal variables too!
Last edited by bdeshi on 16 May 2014 16:52, edited 1 time in total.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 67114
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: [SC] Variable name contain <var>

Post by admin »

Where is this cemetry of old Flux wishes? Seems to be a gold mine... :)

admin
Site Admin
Posts: 67114
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: [SC] Variable name contain <var>

Post by admin »

binocular222 wrote:Yeah, sorry, I found my mistake.
But why not expand the dereference operator to normal variable, not just global/perm?
I did. Check out the change log...

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

Re: [SC] Variable name contain <var>

Post by FluxTorpedoe »

admin wrote:Where is this cemetry of old Flux wishes? Seems to be a gold mine... :)
Well, there's lots more where that came from… :P
This week's were voiced via forum or PM, but I've a nice bunch waiting for you… undisclosed — to spare me a shameful :bug: status! :kidding:

admin
Site Admin
Posts: 67114
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: [SC] Variable name contain <var>

Post by admin »

Keep them if you can. I enjoy getting ideas myself much more than being fed with the ideas of others. :)

Post Reply