How to reference the value of an environment variable with using another environment variable value in variable name?

Improster8

I know that similar questions have been asked before and I have seen them but neither does !var[%Z%]! nor %var[!Z!]% work here:

@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

I tried them and they don't work. What can I do?

Data is a file with following lines:

A
B
C
D
E
F
AA
AB
AC
AD
Compo

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to print environment variable value in shell of a variable whose name is present in another variable value

How to set a postman environment variable's value to another variable's?

Choose an environment variable based on the branch name and store its value to another environment variable

How can I set a runtime environment variable based on the value of another

how to use the value of a variable as the name of another variable

How to read value of variable, where the name of variable is the value of another variable

How to set the value of a macro using environment variable or command line in verilog?

PowerShell - How to get Environment Variable value using wildcards

How to set numeric value in environment variable

How to combine two environment variable in @Value annotation

How to send the value of a windows environment variable?

How to use value of environment variable in project file?

How to show an environment variable's current value?

Getting value of environment variable in unix

quotes in Windows environment variable value

Webpack not assigning value to environment variable

Getting environment variable value in java

Get environment variable value in Dockerfile

systemd: default value for environment variable

Changing a value in the Path environment variable

Check Environment Variable Value in Powershell

Set return value as environment variable

Javascript using a variable value as a name reference

set a variable based on the value of an environment variable

Assigning an environment variable's value to a helm variable

How can assign the value of a sensitive output variable to an environment variable?

How to change the name of an environment variable with a different variable?

How do I store textbox name reference in a Variable to later assign the value of that textbox to another variable

Environment variables and variable name