批量IF报表限制/发行

时间:2017-04-06 13:51:39

标签: batch-file if-statement cmd

嘿,有人看到这个! 所以,我遇到了一些我一直在编写的批处理代码的问题(见下文)。 我正在尝试制作一个易于使用且简单易用的桌面助手。但那不是我的问题。问题集中在程序的“定义”功能上。每当测试文件时,我都可以获得所有当前定义到AB,但随后列表中断(参见输出的表示)。定义应该是空格。另外,请记住,我知道这不实用,但我希望代码尽可能简单。

@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,您的虚拟助手

按任意键继续......

(屏幕清除)

欢迎,汤姆!

按任意键继续......

(屏幕清除)

输入命令。 为所有命令键入“help”。

  

定义

请输入您想要在下面定义的单词。 请使用正确的大写和标点符号! (例子:不, 阿芙罗狄蒂等等) 对于缩写,例如U.S.A.或E.U.,不包括句号! (例如:美国)

  

土豚

名词:1夜间蚂蚁吃非洲哺乳动物

  

定义

(与上述相同)

  

ABA

&GT;

那么,任何人都可以帮我解决这个问题吗? 谢谢!

1 个答案:

答案 0 :(得分:1)

在&#34; AB&#34;的定义中,&#34;(加拿大)&#34;中的右括号。正在提前关闭if语句并将set word=goto line放在条件之外,这意味着一旦你选择了一个单词,它就会一直运行。#34; AB。&#34;

要解决此问题,请使用^来避开右括号。

echo 2. Alberta (Canada^)