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)


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


> 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 "N=20"
CALL ECHO:%%P1:~0,%N%%%

Kind regards

Thread locked

Messages in this Thread

95,060 Postings in 11,983 Threads, 350 registered users, 32 users online (0 registered, 32 guests)
Index | Admin contact |   Forum Time: Aug 3, 2020 - 8:17 am EDT  |  Hits:32,787,039  (10,240 Today )
RSS Feed