I know a similar question has been asked before and i have seen it but neighter does !var[%Z%]! or %var[!Z!]% works in:
@echo off
@echo off
set Z=0
setlocal enabledelayedexpansion
set count=0
for /f "tokens=*" %%x in (Data) do (
set /a count =1
set var[!count!]=%%x
)
:end
cls
echo %var[!Z!]%
choice /N /C QE
IF %errorlevel% == 1 GOTO ZP
IF %errorlevel% == 2 GOTO ZM
pause >nul
goto :end
:ZP
set /a Z=%Z% 1
goto :end
:ZM
set /a Z=%Z%-1
goto :end
Trust me, i tried them and they don't work what can i do?
Data is
A
B
C
D
E
F
AA
AB
AC
AD
CodePudding user response:
I'm assuming that this was your intention, (small modifications included). i.e. to be able to two way cycle through the data items using the Q and E keys.
Code as per the suggestion in my comment:
@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
Set /A "Z=count=0"
Setlocal EnableDelayedExpansion
For /F "Tokens=* UseBackQ" %%G In ("Data.ext") Do (
Set /A count = 1
Set "var[!count!]=%%G"
)
Set "count="
:End
ClS
Echo(!var[%Z%]!
%SystemRoot%\System32\choice.exe /C QE /N
If ErrorLevel 2 GoTo ZM
GoTo ZP
Pause 1>NUL
GoTo End
:ZP
Set /A Z = 1
GoTo End
:ZM
Set /A Z -= 1
GoTo End