1.

Solve : Bat file help!?

Answer»

Before reading i want you to know that my english is not good...
Hey i made a easy transolater like this:

echo off

:trans
echo off
cls
echo Welcome to Haslien Transolater

echo.
set /p word=Enter english word:
if %word%==hello goto hello
goto account

:hello
cls
echo hello = Hellu
pause
cls
goto trans

----

But when i type a word that have not been added it close itself and i want it to say "This word has not been aded to this transolator
Press anny key to contiue" <--- by pressing a key i want it to go to the start again....IF-THEN-ELSE statements are not a batch strong point, thats one reason why I use C++ or ANOTHER similar language type that can interact at the command shell /console level for stuff like this, but here pasted below is a suggestion to make it WORK in batch.

Code: [Select]@echo off

set answer=one
if not "%1" == "1" (
set answer=two
if not "%1" == "2" (
goto bad_argument
)
)

echo Argument %1 is %answer%
goto end


:bad_argument
echo Bad Argument

:end
From: http://forums.codeguru.com/showthread.php?377124-RESOLVED-batch-IF-ELSE-STATEMENTQuote from: DaveLembke on May 10, 2013, 04:11:13 PM

IF-THEN-ELSE statements are not a batch strong point

If "%condition%"=="TRUE" (
echo Yes
) else (
echo No
)
@echo off
cls
echo Welcome to Haslien Transolater
:trans

REM The word English starts with a capital E

set /p word="[0 to quit] Enter English word: "
if "%word%"=="0" goto end

REM I use English / French word pairs because
REM I don't know what language you are using

REM Use /i to ignore case
if /i "%word%"=="cat" goto cat
if /i "%word%"=="dog" goto dog
if /i "%word%"=="man" goto man
if /i "%word%"=="hat" goto hat
if /i "%word%"=="pig" goto pig

REM if you get here then word not in list
Echo Error: %word% not in list
goto trans

:cat
echo %word% = chat
goto trans

:dog
echo %word% = chien
goto trans

:man
echo %word% = homme
goto trans

:hat
echo %word% = chapeau
goto trans

:pig
echo %word% = cochon
goto trans

:end
echo Finished
Pause

Screen output:

Welcome to Haslien Transolater
[0 to quit] Enter English word: cat
cat = chat
[0 to quit] Enter English word: hat
hat = chapeau
[0 to quit] Enter English word: man
man = homme
[0 to quit] Enter English word: pig
pig = cochon
[0 to quit] Enter English word: dog
dog = chien
[0 to quit] Enter English word: TAP
Error: tap not in list
[0 to quit] Enter English word: 0
Finished
Press any key to continue . . .

This is much shorter

@echo off
cls
echo Welcome to Haslien Transolater
:loop
set /p word="[0 to quit] Enter English word: "
if "%word%"=="0" goto end
set trans=$$$$

REM You only have to EDIT here to add / remove word pairs
if /i "%word%"=="cat" set trans=chat
if /i "%word%"=="dog" set trans=chien
if /i "%word%"=="man" set trans=homme
if /i "%word%"=="hat" set trans=chapeau
if /i "%word%"=="pig" set trans=cochon

if "%trans%"=="$$$$" (
Echo Error: %word% not in list
goto loop
)
echo %word% = %trans%
goto loop
:end
Echo Finished
Pause Suggestion:

if "%word%"=="" (
Echo You entered a blank string
goto loop
)another WAY:

(1) words.txt

cat,chat
dog,chien
man,homme
hat,chapeau
pig,cochon
horse,cheval
sheep,mouton
cow,vache
mouse,souris
bird,oiseau
girl,fille


(2) Batch program in same folder

@echo off
cls
echo Welcome to Translater
:loop
set /p word="[0 to quit] Enter English word: "
if "%word%"=="0" goto end
set trans=$$$
for /f "tokens=1,2 delims=," %%A in (words.txt) do if /i "%word%"=="%%A" set trans=%%B
if "%trans%"=="$$$" (
Echo Bad input or word not in list
goto loop
)
echo %word% = %trans%
goto loop
:end
Echo Finished
Pause


Discussion

No Comment Found