Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: ver in ver  (Read 3649 times)

0 Members and 1 Guest are viewing this topic.

mat123

    Topic Starter


    Hopeful

    Thanked: 16
    • Yes
    • Yes
    • Yes
  • Experience: Familiar
  • OS: Windows XP
ver in ver
« on: June 11, 2010, 06:48:23 PM »
how do i get the echo command in this file to work
:a
set a1=a
set a2=b
set a3=c
set a4=d
set a5=e
set /p b=1-5:
echo %a%b%%
goto a
 (note this is just an example so don't tell me to use
:a
set /p b=1-5:
if %b%=1 echo a
if %b%=2 echo b
if %b%=3 echo c
if %b%=4 echo d
if %b%=5 echo e
goto a
)



Helpmeh



    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: ver in ver
« Reply #1 on: June 11, 2010, 07:37:21 PM »
how do i get the echo command in this file to work
:a
set a1=a
set a2=b
set a3=c
set a4=d
set a5=e
set /p b=1-5:
echo %a%b%%
goto a
 (note this is just an example so don't tell me to use
:a
set /p b=1-5:
if %b%=1 echo a
if %b%=2 echo b
if %b%=3 echo c
if %b%=4 echo d
if %b%=5 echo e
goto a
)

What are you trying to accomplish?

echo %a%%b%

will echo whatever the contents of %a% and %b% on the screen.
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

T.C.



    Beginner

    Thanked: 13
    Re: ver in ver
    « Reply #2 on: June 11, 2010, 07:49:43 PM »
    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?


    mat123

      Topic Starter


      Hopeful

      Thanked: 16
      • Yes
      • Yes
      • Yes
    • Experience: Familiar
    • OS: Windows XP
    Re: ver in ver
    « Reply #3 on: June 11, 2010, 08:35:40 PM »
    desired
    make the ver b=1
    echo %a%b%%
    ver b expands first making it
    echo %a1%
    which is a



    Salmon Trout

    • Guest
    Re: ver in ver
    « Reply #4 on: June 11, 2010, 11:39:54 PM »
    desired
    make the ver b=1
    echo %a%b%%
    ver b expands first making it
    echo %a1%
    which is a

    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:

    Helpmeh



      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: ver in ver
    « Reply #5 on: June 12, 2010, 07:51:26 PM »
    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 > nul
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    Salmon Trout

    • Guest
    Re: ver in ver
    « Reply #6 on: June 13, 2010, 01:04:35 AM »
    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.

    Helpmeh



      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: ver in ver
    « Reply #7 on: June 13, 2010, 06:34:49 AM »
    Use the set command to make a new variable who's name contains the other variables.
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    mat123

      Topic Starter


      Hopeful

      Thanked: 16
      • Yes
      • Yes
      • Yes
    • Experience: Familiar
    • OS: Windows XP
    Re: ver in ver
    « Reply #8 on: June 13, 2010, 07:47:20 AM »
    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%



    Salmon Trout

    • Guest
    Re: ver in ver
    « Reply #9 on: June 13, 2010, 08:48:25 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.