You are not logged in.

#1 25 Aug 2006 03:42

NDog
Member
From: New Zealand
Registered: 31 May 2006
Posts: 121
Website

Making one value get the other value?

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

#2 25 Aug 2006 05:54

//[T.0.P]//
Member
Registered: 12 Aug 2006
Posts: 50

Re: Making one value get the other value?

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

#3 25 Aug 2006 14:32

NDog
Member
From: New Zealand
Registered: 31 May 2006
Posts: 121
Website

Re: Making one value get the other value?

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

#4 26 Aug 2006 01:10

NDog
Member
From: New Zealand
Registered: 31 May 2006
Posts: 121
Website

Re: Making one value get the other value?

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

#5 26 Aug 2006 01:21

NDog
Member
From: New Zealand
Registered: 31 May 2006
Posts: 121
Website

Re: Making one value get the other value?

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

#6 26 Aug 2006 06:40

//[T.0.P]//
Member
Registered: 12 Aug 2006
Posts: 50

Re: Making one value get the other value?

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

#7 26 Aug 2006 10:24

NDog
Member
From: New Zealand
Registered: 31 May 2006
Posts: 121
Website

Re: Making one value get the other value?

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

#8 27 Aug 2006 23:15

//[T.0.P]//
Member
Registered: 12 Aug 2006
Posts: 50

Re: Making one value get the other value?

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. smile

Once you get it down, you'll find out it's very powerful in many ways.

Offline

Board footer

Powered by