Saved Bookmarks
| 1. |
Solve : ver in ver? |
|
Answer» how do i GET the echo command in this FILE to work how do i get the echo command in this file to workWhat are you trying to accomplish? echo %a%%b% will echo whatever the contents of %a% and %b% on the screen.Quote echo %a%b%% The syntax of the command is incorrect. Try echo %a%%b% But the environment variables a thru' e haven't been set so how can they be echo'd? desired make the ver b=1 echo %a%b%% ver b expands first making it echo %a1% which is aQuote from: mat123 on June 11, 2010, 08:35:40 PM desired This will make it clear. Batch language does not have arrays, and since variables are expanded at parse time, it is necessary to use call to echo the created variable in a new process, doubling % or ! characters as necessary. Code: [Select]@echo off :a set a1=a set a2=b set a3=c set a4=d set a5=e set /p b=1-5: echo 1 %%a%b%%% call echo 2 %%a%b%%% goto a Code: [Select]1-5:1 1 %a1% 2 a 1-5:2 1 %a2% 2 b 1-5:3 1 %a3% 2 c 1-5:4 1 %a4% 2 d 1-5:5 1 %a5% 2 e 1-5: I figured out a way a couple years back, and used it in a simulation game. Anyway, look at the code, specifically what I highlighted: @echo off Echo Coin flipper pause > nul set t1g4=0 set t1g5=0 set t1g6=0 set t1g7=0 set t2g4=0 set t2g5=0 set t2g6=0 set t2g7=0 cls :begin set /a scriptcount+=1 set /a rnd=%random%%%2 set /a gc+=1 if %rnd% equ 1 (set /a t1+=1) else (set /a t2+=1) if "%t1%"=="4" set t1=0 & set t2=0 & set /a t1g%gc%+=1 & set gc=0 if "%t2%"=="4" set t1=0 & set t2=0 & set /a t2g%gc%+=1 & set gc=0 set /a total1=%t1g4%+%t1g5%+%t1g6%+%t1g7% set /a total2=%t2g4%+%t2g5%+%t2g6%+%t2g7% cls echo Team 1 Wins: %t1% echo Team 2 Wins: %t2% echo ----- echo Amount of games it took to win series: echo ----- echo Team 1 4 Games: %t1g4% echo Team 1 5 Games: %t1g5% echo Team 1 6 Games: %t1g6% echo Team 1 7 Games: %t1g7% echo ----- echo Team 2 4 Games: %t2g4% echo Team 2 5 Games: %t2g5% echo Team 2 6 Games: %t2g6% echo Team 2 7 Games: %t2g7% set /a total=%total1%+%total2% if %total%==1000 goto done goto begin :done pause > nulQuote from: Helpmeh on June 12, 2010, 07:51:26 PM look at the code, specifically what I highlighted: So how do we use that to do what the OP asks? Because I can't get it to work without doubling up the % signs, and using CALL. Use the set command to make a new variable who's NAME contains the other variables.what i REALLY need it for is if statments example set a=1 :a if %b%==5 goto b set /a r%a%=%random% %%5 if %r%a%%==1 set b=a if %r%a%%==2 set b=b if %r%a%%==3 set b=c if %r%a%%==4 set b=d if %r%a%%==5 set b=e set /a a=%a%+1 goto a echo %r1% %r2% %r3% %r4% %r5% Quote from: Helpmeh on June 13, 2010, 06:34:49 AM Use the set command to make a new variable who's name contains the other variables. I see, you are using the fact that set /a does not need percent signs on the variable name on the left hand side of the equals sign. But if you aren't using numbers, you have to use call and the doubled percent signs I posted above. |
|