-1

I've already created a code but when I'm going to display it i only displays the last number that I entered. Please help me.

@echo off
set /a count = 0
set /p process= How many process: 

:BT
echo BT
FOR /L %%A IN (1,1,%process%) DO (
    set /p bt [%%A]=
    IF %%A == %process% goto AT
)

:AT
echo AT
FOR /L %%A IN (1,1,%process%) DO (
   set /a count = %%A
   set /p at[count]=

   IF %%A == %process% goto TABLE
)

:TABLE
echo                       TABLE

echo PROCESS      AT                    BT
FOR /L %%A IN (1,1,%process%) DO (
    set /a count = %count%+1

    echo  P%%A         %at[count]%   

    IF %%A == %process% goto AWT
)

:AWT

pause
AjV Jsy
  • 5,799
  • 4
  • 34
  • 30
Liezl
  • 1
  • 1
  • 3
    Read about `delayed expansion` as this is a FAQ that is asked regularly. – foxidrive Sep 15 '14 at 12:14
  • 2
    And also avoid spaces in variable names and also before and after equal signs – jeb Sep 15 '14 at 13:25
  • See: http://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990 – Aacini Sep 15 '14 at 20:27

1 Answers1

1
@echo off
set /p process= How many process: 
:BT

echo BT

FOR /L %%A IN (1,1,%process%) DO (
 set /p bt[%%A]=
)

:AT

echo AT

FOR /L %%A IN (1,1,%process%) DO (
 set /p at[%%A]=
)

:TABLE
echo                       TABLE

echo PROCESS      AT                    BT
FOR /L %%A IN (1,1,%process%) DO (
CALL echo  P%%A         %%at[%%A]%%   %%bt[%%A]%%
)

:AWT

pause

GOTO :EOF

Here's a fixed version.

Notes: count is not necessary. %%A contains the index 1..%process%.

spaces on each side of the = in a string-assignment (such as a set /p) are significant, so the space between the bt and [ is removed.

Batch simply charges on through the lines of the program until it encounters goto, call or exit. The tests fo end-of-loop are thus not required - once the for loop ends, batch simply passes onto the next instruction line.

at[count] for instance is a variable name, same as whatever. at[%count%] means at[1]..at[??] depending on the value in count- but only outside of a "block" (parenthesised series of lines). Within a block, at[%count%] means at[??] where ?? is the value of count at the time the for statement was encountered. Thie may even be nothingatall - an empty string (ie at[], which is a valid variablename.)

The call echo method uses a parsing trick to first substitute for %%A (the loop-control or metavariable) then echo %at[2]%. Some people don't like using this method - it's slower than the "as-designed" methods and under rare esoteric conditions may not yield the correct result. There are two "official" methods of accessing the run-time or current value of a variable within a loop - setlocal and using a subroutine call - both of which are extensively documented on SO.

Magoo
  • 77,302
  • 8
  • 62
  • 84