Page 1 of 1

Value of the value set to a variable?

Posted: 26 Nov 2011 21:57
by Cat
Here is an example:

Code: Select all

set test=96
set /p 96="random prompt"

say %96% is set to 7. I want to activate a condition for %test% to check the variable of %96%:

Code: Select all

if %%test%%==7 echo 7
if %!test!%==7 echo 7
if !%test%!==7 echo 7

None of the above works. How do i fix this?

Re: Value of the value set to a variable?

Posted: 26 Nov 2011 22:16
by Rileyh
How is your example relevant to the question? And what do you mean
I want to activate a condition set to %test% to check the variable %96%

But I can propose an answer to your question anyway:

Code: Select all

@echo off &setlocal enabledelayedexpansion
set "test=96"
set /p 96=Enter a value:
if /i _"%test%"==_"(whatever value you want to check for)" (do whatever comes to mind)


Or if you want the user to see the value of %test%:

Code: Select all

@echo off
set "test=96"
set /p 96=Something:
echo %test%

Or:

Code: Select all

@echo off
set "test=if /i _"%96%"==_"(whatever value you want to check for)" (do something)"
set /p 96=Something:
%test%


These are all guesses as a result of what your question poses, so they may not work. You need to re-phrase your question.

Regards,
Rileyh

Re: Value of the value set to a variable?

Posted: 26 Nov 2011 22:31
by Cat
To be more specific, here is the exact portion of code:

Code: Select all

:input
set "X%X%Y%Y%= "
choice /c awsd /n >nul
if %errorlevel%==1 (
   if %Y% GTR 1 (
      set /a Y=%y%-1
      ) else (
      goto lose
   )
)
if %errorlevel%==2 (
   if %x% GTR 1 (
      set /a x=%x%-1
   ) else (
      goto lose
   )
)
if %errorlevel%==3 (
   if %X% LSS 17 (
      set /a X=%x%+1
      ) else (
      goto lose
   )
)
if %errorlevel%==4 (
   if %Y% LSS 25 (
      set /a Y=%Y%+1
   ) else (
      goto lose
   )
)
set target=X%X%Y%Y%
if !%target!%==* set /a coinss+=1
X%X%Y%Y%
set X%X%Y%Y%=²
if %coinss% gtr 5 (
   if X%X%Y%Y%==X%f%Y%t% (
      call :coins
      call :coins
   )
)
)
if %coinss% gtr 20 (
   if X%X%Y%Y%==X%f%Y%t% (
      call :coins
      call :coins
      call :coins
   )
)
if X%X%Y%Y%==X%f%Y%t%call :coins
call :grid
goto input

X is set to 12, Y is set to 17
Target is set to X%X%Y%Y%
I want the condition to activate for the variable '%X%X%Y%Y%%', or %X12Y17%.
This is a loop, so it has to work with X and Y being set to different numbers.
Sorry if this is immensely confusing.

Re: Value of the value set to a variable?

Posted: 27 Nov 2011 01:29
by !k
Cat wrote:None of the above works.
it works for me

Code: Select all

setlocal enabledelayedexpansion
set test=96
set /p 96="random prompt : "
if "!%test%!" == "7" echo Seven
___________
XP SP3 x32

Re: Value of the value set to a variable?

Posted: 27 Nov 2011 10:54
by Cat
it works for me

Code: Select all

setlocal enabledelayedexpansion
set test=96
set /p 96="random prompt : "
if "!%test%!" == "7" echo Seven



That only seems to work with numbers, not text strings:

Code: Select all

setlocal enabledelayedexpansion
set test=cat
set /p 96="random prompt : "
if "!%test%!" == "cat" echo Cat

Re: Value of the value set to a variable?

Posted: 27 Nov 2011 11:12
by Ed Dyreen
'
Cat wrote:That only seems to work with numbers, not text strings:

Code: Select all

setlocal enabledelayedexpansion
set test=cat
set /p 96="random prompt : "
if "!%test%!" == "cat" echo Cat
you are referring to cat, not to 96:

Code: Select all

setlocal enabledelayedexpansion
set test=cat
set /p "cat=random prompt : " %= entering 'cat' evals true =%
if "!%test%!" == "cat" echo Cat