0

i have looked for an answer and have not found one.

@echo off
:a
cls
set /p %a% =
if %a% == 1 goto b
goto c
:b
echo.
echo worked
pause
:C
echo.
echo dident work
pause

i set a = 1 and is said that the goto command was unexpected at this time. any help would be great

Changed

ok it has been change and a new problem occurs. now when a = 1 it always goes to c not b

@echo off
:a
cls
set /p a = 
if "%a%" == "1" goto b
goto c
:b
echo.
echo worked
pause
:C
echo.
echo wierd
pause
Chris
  • 82
  • 12
  • For an explanation as to why your code is failing, look at the answers to this question: [Declaring and using a variable in DOS/Windows batch file (.BAT)](http://stackoverflow.com/q/10552812/1012053) – dbenham Apr 06 '14 at 01:54
  • thanks that helped it works now – Chris Apr 06 '14 at 03:07

3 Answers3

0

change this:

set /p %a% =

to

set /p a=

and

if %a% == 1 goto b

to

if "%a%" EQU "1" goto b
npocmaka
  • 53,069
  • 18
  • 138
  • 177
0
@echo off&cls
set /p a=Enter a number : 
if "%a%" EQU "1" goto:b
echo dident work
exit/b

:b
echo Result = 1
SachaDee
  • 9,017
  • 3
  • 20
  • 31
0
@echo off  
echo.  
set /p a=  
echo.  
if %a%==1 goto b  
if not %a%==1 goto c  
:b  
echo worked  
echo.  
pause  
exit  
:c  
echo dident work  
echo.  
pause  
exit  
Syed Galib
  • 88
  • 8