0

ive tried to make a dictionary program...

echo off
Title Afrikaans-English Dictionary
color 0A
cls
echo Created by TheAsainBuffalo
echo Created on 2015-07-25
echo Last Updated 2015-07-25
echo =============================
:Again
set /p Answer=Type in Afikaans Word: 
if %Answer%==afsluit echo English Meaning: to finish
if %Answer%==afrighter echo English Meaning: coach
if %Answer%==agterbland echo English Meaning: blankcover
if %Answer%==aktueel echo English Meaning: actual
if %Answer%==atletiekbaan echo English Meaning: athletics track
if %Answer%==bannoppervlak echo English Meaning: track
if %Answer%==bespeigel echo English Meaning: contemplate
if %Answer%==bespreek echo English Meaning: discuss
if %Answer%==bladsynommer echo English Meaning: page number
if %Answer%==boodskiet echo English Meaning: archery
if %Answer%==draf echo English Meaning: jog
if %Answer%==fiksie echo English Meaning: fiction
if %Answer%==flapteks echo English Meaning: blurb
if %Answer%==hawermout echo English Meaning: oats
if %Answer%==heuweloefeninge echo English Meaning: hill exercises
if %Answer%==hoofkarakter echo English Meaning: protagonist
if %Answer%==illustrasie echo English Meaning: illustration
if %Answer%==inheems echo English Meaning: indigenous
if %Answer%==inhoudsopgowe echo English Meaning: index
if %Answer%==inligting echo English Meaning: information
if %Answer%==inligtingsboeke echo English Meaning: 
if %Answer%==juig echo English Meaning: cheer/applaud
if %Answer%==krale echo English Meaning: beads
if %Answer%==maatskappy echo English Meaning: company
if %Answer%==muurbal echo English Meaning: squash
if %Answer%==nie-fiksie echo English Meaning: non-fiction
if %Answer%==oefeninge echo English Meaning: practice/training
if %Answer%==oplossings echo English Meaning: solutions
if %Answer%==opwarmingsoefeinge echo English Meaning: warm ups
if %Answer%==outeur echo echo English Meaning: author
if %Answer%==pedry echo English Meaning: equestrain
if %Answer%==reken echo English Meaning: desktop
if %Answer%==rekenaar echo English Meaning: PC/Computer
if %Answer%==riller echo English Meaning: thriller (book)
if %Answer%==roei echo English Meaning: paddling
if %Answer%==selfversekerd echo English Meaning: confident
if %Answer%==speurder echo English Meaning: detective
if %Answer%==spieël echo English Meaning: mirror
if %Answer%==spieel echo Possible English Meaning: mirror
if %Answer%==sterspronge echo English Meaning: star jumps
if %Answer%==steun echo English Meaning: support
if %Answer%==stopharlosie echo English Meaning: stopwatch
if %Answer%==tafeldoek echo English Meaning: tablecloth
if %Answer%==teneergedruk echo English Meaning: depressed
if %Answer%==titel echo English Meaning: title
if %Answer%==tjiekilit echo English Meaning: chicklit (book)
if %Answer%==trampopies echo English Meaning: drummies
if %Answer%==tydskrif echo English Meaning: magazine
if %Answer%==verbysteek echo English Meaning: pass
if %Answer%==visie echo English Meaning: pass
if %Answer%==vlugbal echo English Meaning: volleyball
if %Answer%==voorbland echo English Meaning: front cover
if %Answer%==waarheid echo English Meaning: truth
if %Answer%==weerkaatsing echo English Meaning: reflection
if %Answer%==wegspringblokke echo English Meaning: starting blocks
goto Again
::Finished until 18 Feb 2015 (boodskiet)

however i wanted to make it easier by just having something like

set waarheid=truth
set weerkaatsing=reflection
set (Afrikaans Word)=(English Word)
set /p Answer=Type in Afrikaans Word: 
echo Definition %Answer%

Sorry if I'm such a newbie or whatever... My problem is that I need the User Input to prompt the English Word/Meaning of the Afrikaans Word if that makes any sense... Thanks if anyone tried to help!

seven-phases-max
  • 11,765
  • 1
  • 45
  • 57

3 Answers3

1

I would use an external text file as "database":

afsluit=to finish
afrighter=coach
agterbland=blankcover
aktueel=actual
atletiekbaan=athletics track
etc. etc. etc.

shortening your batch file to "code only":

:Again
set "Answer="
set /p "Answer=Type in Afikaans Word: "
if "%Answer%"=="" goto :Again
for /f "tokens=1,2 delims==" %%i in ('findstr /i /b /c:"%Answer%" dictionary.txt') do (
  echo the english term for %%i is %%j.
)
if /i "%Answer%" neq "exit" goto :Again
echo bye.

of course, this is only the basics. There should also be some more error testing ("word not in database")

Stephan
  • 53,940
  • 10
  • 58
  • 91
0

This type of applications are written in a much simpler way with the aid of an array. In the solution below, the translation array is stored in the same Batch file, so no additional data file is needed.

Also, this program have an interesting trick: it helps you to easily define new translation terms!

@echo off
setlocal EnableDelayedExpansion

Title Afrikaans-English Dictionary
color 0A
cls
echo Created by TheAsainBuffalo
echo Created on 2015-07-25
echo Last Updated 2015-07-25
echo =============================

call :CreateTranslationArray

:Again
echo/
set "Afrikaans="
set /p "Afrikaans=Type in Afrikaans Word: "
if not defined Afrikaans goto :EOF
if defined English[%Afrikaans%] (
   echo English Meaning: !English[%Afrikaans%]!
) else (
   echo I don't know the English translation of Afrikaans "%Afrikaans%" yet
   set /P "English=Please give me such translation: "
   set "English[%Afrikaans%]=!English!"
   echo set "English[%Afrikaans%]=!English!">> "%~F0"
)
goto Again
::Finished until 18 Feb 2015 (boodskiet)

:CreateTranslationArray
set "English[afsluit]=to finish"
set "English[afrighter]=coach"
set "English[agterbland]=blankcover"
set "English[aktueel]=actual"
set "English[atletiekbaan]=athletics track"
Community
  • 1
  • 1
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • do you know, if there is a limit for environment variables (memory)? (I'm not sure, that's why I put the data in an extra file (could also be the end of the batch file , if a "single file solution" is preferred) – Stephan Jul 25 '15 at 13:06
  • @Stephan: The maximum environment size is 64 MB. See the Note below "Setting environment variables" at [this link](http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=true) – Aacini Jul 25 '15 at 13:19
  • Should be enough... Thank you for this info, I couldn't find it ad hoc. – Stephan Jul 25 '15 at 13:37
0

You can embed the dictionary after your code within your script, and use FINDSTR to locate the correct word pair, and FOR /F to parse the result.

Below is a nifty version that supports both Afrikaans to English, and English to Afrikaans. Yet it only requires one dictionary, and the exact same code for both!. I make heavy use of double expansion, as in !%var%!.

echo off
setlocal enableDelayedExpansion
Title Afrikaans-English Dictionary
color 0A
set "input=Afrikaans"
set "output=English"
set "beginEnglishSearch=^:::.*:"
set "beginAfrikaansSearch=^:::"
set "endEnglishSearch=$"
set "endAfrikaansSearch=:"
cls

:Prompt
set "word="
set /p "word=Type in %input% Word (or + to switch):"
if not defined word (
  color
  title Command Prompt
  exit /b
)
if "!word!"=="+" (
  set "input=%output%"
  set "output=%input%"
  cls
  goto :Prompt
)
::Result
cls
(
  for /f "tokens=1,2 delims=:" %%A in (
    'findstr /ric:"!begin%input%Search!!word!!end%input%Search!" "%~f0"'
  ) do (
    set "Afrikaans=%%A"
    set "English=%%B"
  )
) && (
  echo %input%: !%input%!
  echo %output%: !%output%!
) || (
  echo !word! not found.
)
echo(
echo(
goto :Prompt

::---------- Afrikaans-English Dictionary below ---------------
:::afsluit:to finish
:::afrighter:coach
:::agterbland:blankcover
:::aktueel:actual
:::atletiekbaan:athletics track
:::bannoppervlak:track
:::bespeigel:contemplate
:::bespreek:discuss
:::bladsynommer:page number
:::boodskiet:archery
:::draf:jog
:::fiksie:fiction
:::flapteks:blurb
:::hawermout:oats
:::heuweloefeninge:hill exercises
:::hoofkarakter:protagonist
:::illustrasie:illustration
:::inheems:indigenous
:::inhoudsopgowe:index
:::inligting:information
:::inligtingsboeke:
:::juig:cheer
:::krale:beads
:::maatskappy:company
:::muurbal:squash
:::nie-fiksie:non-fiction
:::oefeninge:training
:::oplossings:solutions
:::opwarmingsoefeinge:warm ups
:::outeur:author
:::pedry:equestrain
:::reken:desktop
:::rekenaar:computer
:::riller:thriller
:::roei:paddling
:::selfversekerd:confident
:::speurder:detective
:::spieël:mirror
:::spieel:mirror
:::sterspronge:star jumps
:::steun:support
:::stopharlosie:stopwatch
:::tafeldoek:tablecloth
:::teneergedruk:depressed
:::titel:title
:::tjiekilit:chicklit
:::trampopies:drummies
:::tydskrif:magazine
:::verbysteek:pass
:::visie:pass
:::vlugbal:volleyball
:::voorbland:front cover
:::waarheid:truth
:::weerkaatsing:reflection
:::wegspringblokke:starting blocks
dbenham
  • 127,446
  • 28
  • 251
  • 390