You are not logged in.
Pages: 1
Hey there i was wondering how to do this. I am not sure what it is called so I have included an example and what I am trying to achieve.
SET KEY1=abcd
SET KEY2=efgh
SET KEY3=ijkl
SET NUMBER=1
SET X=KEY%NUMBER%
If I type echo %x% it will say KEY1. What I am trying to achieve is to make X output the value of KEY1 which is abcd. etc
So I want to do, is make a variable value called NUMBER, which then can output the vaue of the KEY%NUMBER% if you understand what I mean.
Sorry I don't know what this is called, so using google or this site wasn't much help. If you know what this is called that would be great if you could tell me as well.
Thanks heaps
Nathan
cmd, vbs, ps, bash
autoit, python, swift
Offline
Wow. I was going to tell you that you couldn't do such a thing until I tried it myself and it worked!
The CALL function does wonders it seems, this is how you would do it.
call set X=%KEY%NUMBER%%
Offline
That worked great thanks for that. I only thought the call command could open other batch files in the same window, but I will do a bit of research now. Cheers.
cmd, vbs, ps, bash
autoit, python, swift
Offline
This code doesn't work. What am I doing wrong?
CD\
SET KEY1=cl_cdkey 123456789
SET NUMBER=1
CALL SET X=%KEY%NUMBER%%
ECHO %NUMBER%
ECHO %KEY1%
ECHO %X%
pause
cmd, vbs, ps, bash
autoit, python, swift
Offline
I think it doesnt work in a batch file. Only in the command prompt window which means you need double quotes or somethng?
cmd, vbs, ps, bash
autoit, python, swift
Offline
Sorry about that.
Here is an alternative. Although it's rather code lengthy:
for /F "delims== tokens=1*" %%g in ('set KEY%NUMBER%') do set X=%%h
pretty much here you send the output of set KEY1 to the variable X leaving out the KEY1= part.
Offline
That worked fine. CALL SET X=%%KEY%NUMBER%%% will work as well. I still cant figure out how FOR command works, I have tired to study it, but I just cant my head around how it works, but thanks for that it was good.
cmd, vbs, ps, bash
autoit, python, swift
Offline
cool. call set %%KEY%NUMBER%%%, i'll have to remember that.
yeah I know what you mean about the FOR command, sort of works like a for loop, but then it doesnt', or it does but then only to a certain extent, or the other way around.
Once you get it down, you'll find out it's very powerful in many ways.
Offline
Pages: 1