4

Anything put into this part of this batch file automatically goes to :yes, regardless of whether the string is contained in MRSVANDERTRAMP.txt or not.

:enterverb
set /p id=Enter Verb: 

findstr /m %id% MRSVANDERTRAMP.txt
if %errorlevel%==0 (
goto :yes 
) else (
goto :no
)

:no
echo Verb does not take etre in the Perfect Tense. 
pause
goto :option0

:yes
echo Verb is a MRSVANDERTRAMP verb and takes etre in the Perfect Tense.
pause
Max Hallam
  • 85
  • 1
  • 2
  • 7

4 Answers4

1

I came up with a similar code to test it, and it works.

@echo off
@title TEST

:main
set /p word=Write a word: 

findstr /M %word% words.txt

if "%errorlevel%" == "0" ( echo FOUND ) else ( echo NOT FOUND )
pause>nul
cls && goto main




Maybe there's a problem with the IF statement.. Try using
if "%errorlevel%" == "0" 

insead of

if %errorlevel%==0
0

This works fine. You might like to surround "%id%" in double quotes as shown, to protect against some poison characters though.

@echo off

echo one>MRSVANDERTRAMP.txt
echo two>>MRSVANDERTRAMP.txt


:enterverb
set /p id=Enter Verb: 

findstr /m %id% MRSVANDERTRAMP.txt
if %errorlevel%==0 (
goto :yes 
) else (
goto :no
)

:no
echo Verb does not take etre in the Perfect Tense. 
pause
goto :option0

:yes
echo Verb is a MRSVANDERTRAMP verb and takes etre in the Perfect Tense.
pause

:option0
echo done
pause
foxidrive
  • 40,353
  • 10
  • 53
  • 68
0

Dude try this

enterverb

set /p id=Enter Verb: 
findstr /m %id% MRSVANDERTRAMP.txt

set a=0

if %errorlevel%== %a% (
goto :yes 
) else (
goto :no
)

:no
echo Verb does not take etre in the Perfect Tense. 
pause
goto :option0

:yes
echo Verb is a MRSVANDERTRAMP verb and takes etre in the Perfect Tense.
Stephan
  • 53,940
  • 10
  • 58
  • 91
NecroBit
  • 1
  • 1
0

I had the same problem in this code:

@echo off

ping www.google.com
if %errorlevel%== 0 (
goto :ok
) else (
go to :fail
)

:ok
echo ok
pause

:fail
echo fail
pause

Always go to :ok but with a set off var=0 my problem is solved and my code runs.

@echo off
ping www.google.com
set a=0
if %errorlevel%== %a% (
goto :ok
) else (
goto :fail
)

:ok
echo ok
pause


:fail
echo fail
pause
Nima Soroush
  • 12,242
  • 4
  • 52
  • 53
NecroBit
  • 1
  • 1