ZTree.com  | ZEN  | About...  

 Index   Back

[Q] N=20, ECHO %%%P1:~0,%%N%%%%, how can i make it work? [Bug?]   [Q]

By: Nick Williams     West Sussex, England (forum time +5 hrs)  
Date: Aug 28,2017 at 21:02
In Response to: [Q] N=20, ECHO %%%P1:~0,%%N%%%%, how can i make it work? [Bug?] (Ryan)

> SET P1=AAAABBBBBBBB
> DDDDDDDDDDDDDDDDDAAAAAAAAAAAAAAAAA

Is the gap in "P1" intentional ? If so, you will need to use double quotes, like this:-


SET "P1=AAAABBBBBBBB DDDDDDDDDDDDDDDDDAAAAAAAAAAAAAAAAA"


> AA=works in ztreemenu
> ECHO %P1:~0,78%
>
> BB=works in command line but not in ztreemenu as it was meant to
> SET N=20
> ECHO %%P1:~0,%N%%%
>
> CC=doesnt work in ztreemenu, i think it is a bug in ztree
> so i started adding more %'s hoping it to work, but no luck so far
>
> SET N=20
> ECHO %%%P1:~0,%N%%%% no work in ztree
> ECHO %%%P1:~0,%%N%%%% no work in ztree
> ECHO %%%P1:~0,%%N%%%%% no work in ztree
>
> how can i make it work?
>
> but without using delayed expansion... which i havent tried yet
>
> sometimes adding 1 more % doesnt work, and i have been blindly adding
> %'s until it worked, then it worked, but no luck with AA=

Ryan, the best bit of advice I can give you is to use batch (.BAT or .CMD) files for your code, not ZTreeMenu. There's nothing wrong with ZTreeMenu - there's certainly no bugs in it as you suggested. It's just that ZTreeMenu requires you to double-up all those percent signs, and it can get a bit confusing. Use ZTreeMenu to launch your batch files when they are ready. The best of both worlds, that way.

It's no good adding percent signs in an ad-hoc manner, hoping to get something working. The percent signs are very meaningful, you will need to understand their significance if you want to write powerful code.

Try this:-


:: Paste the following into a batch file and run it from a CMD Prompt ...
::
SET "P1=AAAABBBBBBBB DDDDDDDDDDDDDDDDDAAAAAAAAAAAAAAAAA"
SET "N=20"
CALL ECHO:%%P1:~0,%N%%%


Kind regards
Nick

270 views      
Thread locked
 

Messages in this Thread

 
94,590 Postings in 11,932 Threads, 348 registered users, 19 users online (0 registered, 19 guests)
Index | Admin contact |   Forum Time: Nov 20, 2019 - 7:02 am EST  |  Hits:29,193,209  (6,450 Today )
RSS Feed