how can i give a variable to a case like this?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nnnmmm
Posts: 141
Joined: 26 Aug 2017 06:11

how can i give a variable to a case like this?

#1 Post by nnnmmm » 28 Aug 2017 06:50

Code: Select all

AA=
SET P1=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATTTTTTTTAAAAAA
SET P2=NNNNNNNNNNNNNNNNNNNAAAAAAAAAAAAAAA
SET P3=AAAAAADDDDDDDDDDDDDDDDDAAADDDAAAAAAAAAAAA
ECHO 1. %P1:~0,78%
ECHO 2. %P2:~0,78%
ECHO 3. %P3:~0,78%


how can i give a variable to a case like this for an easy control?

Code: Select all

BB=
SET AA=50
ECHO 1. %P1:~0,AA%
ECHO 2. %P2:~0,AA%
ECHO 3. %P3:~0,AA%

BB= doesnt work because it doesnt do ECHO 1. %P1:~0,%AA%%

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: how can i give a variable to a case like this?

#2 Post by Compo » 28 Aug 2017 07:06

Either like this:

Code: Select all

SET "P1=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATTTTTTTTAAAAAA"
SET "P2=NNNNNNNNNNNNNNNNNNNAAAAAAAAAAAAAAA"
SET "P3=AAAAAADDDDDDDDDDDDDDDDDAAADDDAAAAAAAAAAAA"

SET "AA=26"
SETLOCAL ENABLEDELAYEDEXPANSION
ECHO 1. !P1:~,%AA%!
ECHO 2. !P2:~,%AA%!
ECHO 3. !P3:~,%AA%!
Or like this:

Code: Select all

SET "P1=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATTTTTTTTAAAAAA"
SET "P2=NNNNNNNNNNNNNNNNNNNAAAAAAAAAAAAAAA"
SET "P3=AAAAAADDDDDDDDDDDDDDDDDAAADDDAAAAAAAAAAAA"

SET "AA=26"
CALL ECHO 1. %%P1:~,%AA%%%
CALL ECHO 2. %%P2:~,%AA%%%
CALL ECHO 3. %%P3:~,%AA%%%

nnnmmm
Posts: 141
Joined: 26 Aug 2017 06:11

Re: how can i give a variable to a case like this?

#3 Post by nnnmmm » 28 Aug 2017 09:11

thanks very much,worked.

nnnmmm
Posts: 141
Joined: 26 Aug 2017 06:11

Re: how can i give a variable to a case like this?

#4 Post by nnnmmm » 29 Aug 2017 19:22

>CALL ECHO 1. %%P1:~,%AA%%%

why do you need "call" in there? i thought it worked because it had the correct % numbers, but it was the call that did it, somehow my brain ignored the word "call" everywhere and tried ECHO 1. %%P1:~,%AA%%% in a new batch and it didnt work. just strange how brian works.

copy paste to test the code?
then i actually write it in a different syntax.....

Post Reply