2017-04-06 60 views
-1

嘿有人看這個! 所以,我遇到了一些我一直在寫的批處理代碼的問題(見下文)。 我試圖製作一個易於使用和簡單的全能桌面助理。但那不是我的問題。問題集中在程序的「定義」功能上。無論何時測試該文件,我都可以將所有當前定義提交到AB,但是這個列表會被截斷(請參閱輸出表示)。定義應該是空白的空間。另外,請記住,我知道這是不實際的,但我希望代碼儘可能簡單。批量IF聲明限制/問題

@echo off 


:processes 
color 0a 
title Kapua, Your Virtual Assistant 
cd ./Info 
set /p name=<name.txt 
set /p food=<food.txt 
set /p color=<color.txt 
set /p game=<game.txt 
set /p friend=<friend.txt 
set /p movie=<movie.txt 


:start 
cls 
echo. 
echo Kapua, Your Virtual Assistant 
echo. 
pause 
goto welcome 


:welcome 
cls 
echo. 
echo Welcome, %name%! 
echo. 
pause 
cls 
goto main 


:main 
echo. 
echo Enter a command. 
echo Type "help" for all commands. 
echo. 
goto line 


:line 
set /p command=">" 
if not defined command (
echo. 
echo Pardon? 
echo. 
set command= 
goto line 
) 
if %command% == help (
set command= 
goto help 
) 
if %command% == define (
set command= 
goto define 
) 
if %command% == clear (
set command= 
goto clear 
) 


:help 
echo. 
echo Current available commands and functions: 
echo. 
echo "help" - displays the current available commands and functions 
echo "define" - defines a word 
echo "clear" - clears the current screen 
echo. 
goto line 


:clear 
cls 
echo. 
goto line 


:define 
echo. 
echo Please type the word you want defined below. 
echo Please use proper capitalization and punctuation! (Example: don't, 
echo Aphrodite, et cetera) 
echo For abbreviations, such as U.S.A. or E.U., don't include periods! 
echo (Example: USA) 
echo. 
set /p word=">" 
if not defined word (
echo. 
echo Pardon? 
set word= 
goto define 
) 

if %word% == a (
echo. 
echo Noun: 1. the first letter of the alphabet 
echo. 
echo Indefinite Article/Adjective: 1. one; one sort of 
echo        2. each; any one 
echo. 
echo Prefix: 1. in, into, on, at, to 
echo   2. in the act or state of 
echo   3. up, out 
echo   4. off, of 
echo   5. not, without 
echo. 
echo *Used before words beginning with a consonant sound 
echo. 
set word= 
goto line 
) 

if %word% == A (
echo. 
echo Noun: 1. a blood type 
echo  2. a grade indicating excellence 
echo  3. the sixth tone in the scale of C major 
echo. 
set word= 
goto line 
) 

if %word% == AA (
echo. 
echo Abbreviation: 1. Alcoholics Anonymous 
echo    2. Associate in/of Arts 
echo. 
set word= 
goto line 
) 

if %word% == aardvark (
echo. 
echo Noun: 1. a nocturnal, ant-eating African mammal 
echo. 
set word= 
goto line 
) 

if %word% == Aaron (
echo. 
echo Noun: the first high priest of the Hebrews 
cho. 
set word= 
goto line 
) 

if %word% == AB (
echo. 
echo Noun: 1. a blood type 
echo. 
echo Abbreviation: 1.Bachelor of Arts 
echo    2. Alberta (Canada) 
echo. 
set word= 
goto line 
) 

if %word% == ab (
echo. 
echo Prefix: 1. away, from, from off, down 
echo. 
set word= 
goto line 
) 

if %word% == ABA (
echo. 
echo Abbreviation: 1. American Bar Association 
echo. 
set word= 
goto line 
) 

if %word% == aback (
echo. 
echo Adverb: 1. backward, back 
echo. 
set word= 
goto line 
) 

if %word% == abacus (
echo. 
echo Noun: 1. a frame with sliding beads for doing arithmetic 
echo. 
echo Plural: 1. abacuses 
echo   2. abaci 
echo. 
set word= 
goto line 
) 

if %word% == abaft (
echo. 
echo Adverb: 1. in or behind the stern of a ship 
echo. 
echo Preposition: 1. nearer the stern than; behind 
echo. 
set word= 
goto line 
) 

if %word% == abalone (
echo. 
echo Noun: 1. an edible sea mollusk with an oval, somewhat spiral shell 
echo. 
set word= 
goto line 
) 

輸出(用於變量的緣故,我只是取代隨機的東西):

Kapua,你的虛擬助理

按任意鍵繼續......

(清屏)

歡迎,湯姆!

按任意鍵繼續......

(清屏)

輸入的命令。 輸入所有命令的「幫助」。

定義

請鍵入您希望下面定義的詞。 請使用適當的大小寫和標點符號! (例如:不要, 阿芙羅狄蒂等) 縮寫,如美國或歐盟,不包括句點! (實施例:美國)

土豚

名詞:1夜行性,螞蟻爲食的非洲哺乳動物

限定

(同上東西)

ABA

>

那麼,誰能幫我解決這個問題? 謝謝!

+1

你真的應該讀一下[mcve]是什麼。 – LotPings

回答

1

在定義爲「AB」,右括號中的「(加拿大),」及早關閉if聲明,並把set word=goto line外界條件的,這意味着它一旦你選擇一個字過去一直被跑「 AB「。

要解決此問題,請使用^來避免左括號。

echo 2. Alberta (Canada^) 
+0

它的工作原理!非常感謝! :) –