the name a variable is a variable

January 29, 2011 at 17:48:09
Specs: Windows XP, 2.591 GHz / 2046 MB
Hello my name is Patrick Gelvin and i am doing the announcements for my school and i was thinking of creating a batch program to tell me what to say so the way is stores the lines (things to say) is by setting the lines to a # through the set /p command and when it retrieves them it uses a separate variable that keeps counting up till it reaches the amount of lines there is but the problem is i cant tell cmd that the # 1 is a variable name because the # 1 is the contents of a variable but also the name of a variable.

here is the code:

@echo off
setLocal EnableDelayedExpansion
set /p lines=
set line#=0
:step1
cls
set /p %line#%=
set /a line#=%line#%+1
if %line#%==%lines% goto step2
goto step1
:step2
set line#=0
:step3
set /a line#=%line#%+1
cls
echo %%line#%%
pause >nul
if %line#%==%lines% goto step4
goto step3
:step4
pause >nul
EndLocal
exit


See More: the name a variable is a variable

Report •


#1
January 30, 2011 at 00:45:40
http://www.computing.net/howtos/sho...

!%var%!

Here is my interpretation:

@echo off
SetLocal EnableDelayedExpansion

:numinput
set numlines=
set /p numlines=Number of lines: 
if not defined numlines goto numinput
for /f "tokens=1,2 delims=0123456789" %%a in ("A0%numlines:"=%") do (
    if not "%%b"=="" goto numinput
)

if %numlines:"=% leq 0 (
    goto numinput
) else set numlines=%numlines:"=%


for /l %%a in (1 1 %numlines%) do (
    cls
    set input%%a=
    set /p input%%a=
)

for /l %%a in (1 1 %numlines%) do (
    cls
    echo.!input%%a!
    pause > nul
)

endlocal
exit /b


Report •

#2
January 30, 2011 at 10:22:56
Ok. that worked and i have no clue why.
probably because i have never heard of the for command but the important thing is that it worked so thanks a lot but i have tried doing !%var%! because someone on his site told me to on a different thread so what was with the ! marks? but thanks a bunch anyways. i will create a batch program testing the ! thingy in many different ways but anyways thanks again. bye.

Report •

Related Solutions


Ask Question