Solved Make Input To Variable Name.

April 2, 2012 at 06:22:53
Specs: Windows 7 Pro, Intel(R) Core(TM) i3 / 3.20 GHz / 8 GB Ram
I need to take user input and make the input a variable name.

set /p input=
set %variable% = "Yes"
^
So inputing 2 will - " set %2% = "Yes" "

Any help would be appreciated.


See More: Make Input To Variable Name.

Report •


✔ Best Answer
April 4, 2012 at 13:35:18
@echo off
:main2

if defined one echo achievment 1 accomplished
if defined two echo achievment 2 accomplished
if defined three echo achievment 3 accomplished
rem etc
set /p achnum=acheivment number :
goto %achnum%

goto main2
:1
set one=1
goto main2
:2
set two=2
goto main2
:3
set three=3
rem etc
goto main2
endlocal

mike



#1
April 2, 2012 at 06:30:44
Read it wrong..

Report •

#2
April 2, 2012 at 06:45:46
So do so. There's nothing that should inhibit you.
Mon 2012.04.02  9.41.30
H:\>set var
Environment variable var not defined

Mon 2012.04.02  9.41.37
H:\>set varName=var

Mon 2012.04.02  9.41.53
H:\>set %varName%=Yes

Mon 2012.04.02  9.42.01
H:\>set var
var=Yes
varName=var

How To Ask Questions The Smart Way


Report •

#3
April 2, 2012 at 07:09:08
The thing was that I need to write set %%input%% = "Yes".

So if the input was 2 it will not be "set 2 = Yes", but "set %2% = Yes"


Report •

Related Solutions

#4
April 2, 2012 at 08:19:23
So you want the user to enter a name of a variable that holds the name of a variable that you want to set to "Yes?" It might be time to rethink what you're doing, and how you're doing it.

How To Ask Questions The Smart Way


Report •

#5
April 2, 2012 at 23:39:01
Yah, that was the idea.

So I made a program to have a list of achiements, and you type the achivements number and it will be able to say "Yes" instead of "No".

And thats really the only thing i am missing.


Report •

#6
April 3, 2012 at 07:31:04
perhaps by using

I need to take user input and make the input a variable name.
set /p input=
set %input% = "Yes"

if you enter 2 @ the set /p input
it would do the following

make a variable %2% that has "Yes" as its data
so if you typed echo %2% it would echo yes

however as the post above stated, i don't think thats what you are looking for.

mike


Report •

#7
April 4, 2012 at 00:08:32
Not entirely sure about that, ehm...

The main code i wrote looks like this:
-----------------------------------------
:main
cls
echo 1) Achiement. (%1%)
echo 2) Achiement. (%2%)
echo 3) Achiement. (%3%)
(And up to 50 achiements.)
set /p input=:
if "%input%" == "save" goto save
if "%input%" == "exit" goto exit
if "%input%" lss "1" goto error
if "%input%" gtr "50" goto error
-----------------------------------------

I haven't continued it from there.

But if that @ can help, could it not be possible to add:
" set "%output%" = "%input% @" "?

If that was what you meant.


Report •

#8
April 4, 2012 at 08:49:06
Sigh, sorry, the @ was at, not a secret code.

your code is confusing, are you trying to have a user input a variable name?

if so that can be accomplished with the set /p variablename=
the variablename being the variable name.
then by using
set %variablename% == yes


you would set whatever the user entered at the line set /p variablename=
to store the word yes
so if the user entered 7 at the line set /p variablename=
then the variable %7% would equal yes


on another note


are you going to ask how many achievments are possible at the begining?

or is the goal to have a separate variable for each achievment?

mike


Report •

#9
April 4, 2012 at 10:07:58
Yes.

I want a list of achievments and have a separate variable for each achievment.

So I can see which achievments I have done.

(There is 50 achievments so meaning 50 separate variables.)

But I still got no idea of even making it possible.


Report •

#10
April 4, 2012 at 13:35:18
✔ Best Answer
@echo off
:main2

if defined one echo achievment 1 accomplished
if defined two echo achievment 2 accomplished
if defined three echo achievment 3 accomplished
rem etc
set /p achnum=acheivment number :
goto %achnum%

goto main2
:1
set one=1
goto main2
:2
set two=2
goto main2
:3
set three=3
rem etc
goto main2
endlocal

mike


Report •

#11
April 4, 2012 at 14:00:31
Oh, that's probably a lot more easily than what I have planned.

But thank you so much for helping me, I really appreciated you time. :)


Report •

#12
April 4, 2012 at 14:20:16
certainly. there are other ways of going about it, wasn't trying to oversimplify

mike


Report •

#13
April 5, 2012 at 01:03:10
By the way, how do you change the title to solved? (It's my first time using this :))

I figured it out, sorry taking you time on this one ;(


Report •

#14
April 5, 2012 at 05:49:11
its cool, i'd rather be wrong, and informed that way I learn something :-)

mike


Report •

#15
April 9, 2012 at 00:11:00
Ehm, not to be annoying but i tried to type this in cmd:

set Input=3
set %Input%=Yes
echo %3%

And it displayed the following:
Yes

So it did work...


Report •

#16
April 10, 2012 at 07:21:20
Sure that's what Razor2.3 was explaining here

set varName=var
:: this defines varName as var
set %varName%=Yes
:: this defines var as Yes?

mike


Report •

#17
April 10, 2012 at 12:35:55
It was just a really long time since I programed batch. (Like a half year ago...)

So I thought to set a variable, you need to type "set %Variable%=Yes"


Report •


Ask Question