ZTree.com  | ZEN  | About...  

 Index   Back

adding 1 more %, doubling it, still dont work, so i was wondering if it was bug   [Q]

By: Nick Williams     West Sussex, England (forum time +5 hrs)  
Date: Aug 29,2017 at 16:19
In Response to: adding 1 more %, doubling it, still dont work, so i was wondering if it was bug (Ryan)

> > SET "P1=AAAABBBBBBBB DDDDDDDDDDDDDDDDDAAAAAAAAAAAAAAAAA"
> > SET "N=20"
> > CALL ECHO:%%P1:~0,%N%%%
This example I gave you, definitely works. Have you actually tried it ?

> BB=works in command line (i meant as in batch)
> SET P1=AAAABBBBBBBB DDDDDDDDDDDDDDDDDAAAAAAAAAAAAAAAAA
> SET N=20
> ECHO %%P1:~0,%N%%%
> it worked in a batch, so it must work in F9(=ztreemenu script)... but
This could not possibly have worked, for 2 reasons:-
(1) As I've already said,


SET P1=AAAABBBBBBBB DDDDDDDDDDDDDDDDDAAAAAAAAAAAAAAAAA
needs double quotes (as in my example).
(2) You're missing the CALL before the ECHO (again, see my example)

> >must double-up all those percent
> but i have this problem, not a problem but more of the definitions that
> are going around
> 1. sometimes % works in F9 without adding more %
> 2. sometimes % works in F9 with adding 1 more %
> 3. sometimes % works in F9 with doubling it
> i always try 1. 2. 3.
Nope, only 3. is correct.

To make my example work in [F9] Menu, you would need to copy and paste it, then double-up the percent signs, as follows:-

SET "P1=AAAABBBBBBBB DDDDDDDDDDDDDDDDDAAAAAAAAAAAAAAAAA"
SET "N=20"
CALL ECHO:%%%%P1:~0,%N%%%%%%
Don't forget to use CALL ECHO

> SetLocal EnableExtensions EnableDelayedExpansion
> SET AA=50
> ECHO !P1:~0,%%AA%%!
> it worked in F9, but DelayedExpansion interferes with the data with
> "!" so badly, this is my last resort to use.
Yes, avoid EnableDelayedExpansion for the reason you've given -- there's no need for it in this particular case.

> > using it SET "A=123" instead of SET A=123
I admit that double quoting SET A=123 is unnecessary -- I do it out of habit.
But try running this line without double quotes:-

SET directory=C:\Documents & Settings
It definitely needs to be:-

SET "directory=C:\Documents & Settings"

Hope this helps. Just so you know, I would never send you (or anybody) any code examples if I hadn't tested them first.


Kind regards
Nick

279 views      
Thread locked
 

Messages in this Thread

 
94,590 Postings in 11,932 Threads, 348 registered users, 19 users online (2 registered, 17 guests)
Index | Admin contact |   Forum Time: Nov 20, 2019 - 11:32 am EST  |  Hits:29,198,074  (11,315 Today )
RSS Feed