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  
Date: Aug 29,2017 at 01: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

949 views      
Thread locked
 

Messages in this Thread

 
96,637 Postings in 12,231 Threads, 350 registered users, 60 users online (0 registered, 60 guests)
Index | Admin contact |   Forum Time: Mar 29, 2024 - 2:37 am UTC  |  Hits:62,389,074  (3,860 Today )
RSS Feed