"设置/ a此时出乎意料"

时间:2016-12-01 06:35:40

标签: batch-file

我是批处理的新手,主要用于这个学校项目。我也是堆叠溢出的新手,所以我会理解错误的宽大处理。我一直收到错误消息"此时设置/ a是意外的"当我到达":MARK"在代码中。我只想把整个代码转储到这里,对不起,如果它令人困惑。

@echo off
color 7C

:MAINMENU
cls
title Main Menu
echo To start the quiz, type 1
echo To view the accreditations, type 2
echo To exit the Shop Quiz, type 3
set/p menuselection= Make your selection: 
if %menuselection%==1 goto QUESTIONONE
if %menuselection%==2 goto ACCREDITATION
if %menuselection%==3 goto ENDPROGRAM

:QUESTIONONE
cls
title Question One of Ten
echo What do you do if there is an accident in the shop?
echo.
echo 1. Duck and cover your head to avoid injury
echo 2. Immediately go tell the instructor
echo 3. Walk it off
echo 4. Help the person who got hurt and fix the problem
echo.
set/p aone=
goto QUESTIONTWO

:QUESTIONTWO
cls
title Question Two of Ten
echo What attitude should you always have in the shop?
echo.
echo 1. Calm and careful
echo 2. Focused on surroundings
echo 3. Mischievous and goofy
echo 4. Attentive and ready to avoid injury
echo.
set/p atwo=
goto QUESTIONTHREE

:QUESTIONTHREE
cls
title Question Three of Ten
echo Which of the following is NOT allowed for dress in shop?
echo.
echo 1. Sandals
echo 2. Tucked Loose clothing
echo 3. Crocs
echo 4. Eye Goggles
echo.
set/p athree=
goto QUESTIONFOUR

:QUESTIONFOUR
cls
title Question Four of Ten
echo What list of items must you be able to locate in the shop?
echo.
echo 1. Wood, tool shelf, eye goggles, fire extinguishers, power buttons
echo 2. Fire blankets, first aid kits, fire extinguishers, power buttons, eye goggles
echo 3. Eyewash stations, first aid kits, fire extinguishers, fire blankets, power buttons
echo 4. Eye goggles, fire blankets, tool shelf, fire extinguishers, power buttons
echo.
set/p afour=
goto QUESTIONFIVE

:QUESTIONFIVE
cls
title Question Five of Ten
echo Which of these potential risks is caused by clutter and spills?
echo.
echo 1. Bumping into things
echo 2. Unnecessary strain
echo 3. The drill catching the stock and spinning it
echo 4. Prevention of proper lifting techniques
echo.
set/p afive=
goto QUESTIONSIX

:QUESTIONSIX
cls
title Question Six of Ten
echo Which of these IS an acceptable mental condition for shop work?
echo.
echo 1. Tired
echo 2. Hesitant
echo 3. Rushed
echo 4. Under the influence
echo.
set/p asix=
goto QUESTIONSEVEN

:QUESTIONSEVEN
cls
title Question Seven of Ten
echo Your work station should NOT be:
echo.
echo 1. Adequately ventilated
echo 2. Well-organized
echo 3. Compact
echo 4. Well-lit
echo.
set/p aseven=
goto QUESTIONEIGHT

:QUESTIONEIGHT
cls
title Question Eight of Ten
echo What tool should you use to secure your work?
echo.
echo 1. Wrench
echo 2. Paper weight
echo 3. Vice
echo 4. Your hand
echo.
set/p aeight=
goto QUESTIONNINE

:QUESTIONNINE
cls
title Question Nine of Ten
echo What can you use to hold onto things like nails, screws, or chisels?
echo.
echo 1. Pocket
echo 2. Hands
echo 3. Mouth
echo 4. All of the above
echo.
set/p anine=
goto QUESTIONTEN

:QUESTIONTEN
cls
title Question Ten of Ten
echo Of the following only one action is acceptable. Select it.
echo.
echo 1. Using files without handles
echo 2. Prying with a chisel
echo 3. Using clamps that are really big
echo 4. Hammering with a wrench
echo.
set/p athree=
goto RESULTS

:RESULTS
cls
title Results
goto MARK

:RESULTONE
echo Question one of ten
echo What do you do if there is an accident in the shop?
if %aone%==1 echo "Duck and cover your head to avoid injury" is wrong.
if %aone%==1 echo Correct answer is 2, "Immediately go tell the instructor"
if %aone%==2 echo "Immediately go tell the instructor" is correct.
if %aone%==3 echo "Walk it off" is wrong.
if %aone%==3 echo Correct answer is 2, "Immediately go tell the instructor"
if %aone%==4 echo "Help the person who got hurt and fix the problem" is wrong.
if %aone%==4 echo Correct answer is 2, "Immediately go tell the instructor"
pause
goto RESULTTWO

:RESULTTWO
echo Question two of ten
echo What attitude should you always have in shop?
if %atwo%==1 echo "Calm and careful" is correct.
if %atwo%==2 echo "Focused on surroungings" is wrong.
if %atwo%==2 echo Correct answer is 1, "Calm and careful"
if %atwo%==3 echo "Mischievous" is wrong. 
if %atwo%==3 echo Correct answer is 1, "Calm and careful"
if %atwo%==4 echo "Attentive and ready to avoid" is wrong. 
if %atwo%==4 echo Correct answer is 1, "Calm and careful"
pause
goto RESULTTHREE

:RESULTTHREE
echo Question three of ten
echo Which of the following is NOT allowed for dress in shop?
if %athree%==1 echo "Sandals" is correct.
if %athree%==2 echo "Tucked loose clothing" is wrong.
if %athree%==2 echo Correct answer is 1, "Sandals"
if %athree%==3 echo "Crocs" is wrong.
if %athree%==3 echo Correct answer is 1, "Sandals"
if %athree%==4 echo "Eye goggles" is wrong.
if %athree%==4 echo Correct answer is 1, "Sandals"
pause
goto RESULTFOUR

:RESULTFOUR
echo Question four of ten
echo What list of items must you be able to locate in the shop?
if %afour%==1 echo "Wood, tool shelf, eye goggles, fire extinguishers, power buttons" is wrong. 
if %afour%==1 echo Correct answer is 3, "Eyewash stations, first aid kits, fire extinguishers, fire blankets, power buttons"
if %afour%==2 echo "Fire blankets, first aid kits, fire extinguishers, power buttons" is wrong.
if %afour%==2 echo Correct answer is 3, "Eyewash stations, first aid kits, fire extinguishers, fire blankets, power buttons"
if %afour%==3 echo "Eyewash stations, first aid kits, fire extinguishers, fire blankets, power buttons" is correct.
if %afour%==4 echo "Eye goggles, fire blankets, tool shelf, fire extinguishers, power buttons" is wrong.
if %afour%==4 echo Correct answer is 3, "Eyewash stations, first aid kits, fire extinguishers, fire blankets, power buttons"
pause
goto RESULTFIVE

:RESULTFIVE
echo Question five of ten
echo Which of these potential risks is caused by clutter and spills
if %afive%==1 echo "Bumping into things" is correct.
if %afive%==2 echo "Unnecessary strain" is wrong.
if %afive%==2 echo Correct answer is 1, "Bumping into things"
if %afive%==3 echo "The drill catching the stock and spinning it" is wrong.
if %afive%==3 echo Correct answer is 1, "Bumping into things"
if %afive%==4 echo "Prevention of proper lifting techniques" is wrong.
if %afive%==4 echo Correct answer is 1, "Bumping into things"
pause
goto RESULTSIX

:RESULTSIX
echo Question six of ten
echo Which of these is an acceptable mental condition for shop work?
if %asix%==1 echo "Tired" is wrong.
if %asix%==1 echo Correct answer is 2, "Hesitant"
if %asix%==2 echo "Hesitant" is correct.
if %asix%==3 echo "Rushed" is wrong.
if %asix%==3 echo Correct answer is 2, "Hesitant"
if %asix%==4 echo "Under the influence" is wrong.
if %asix%==4 echo Correct answer is 2, "Hesitant"
pause
goto RESULTSEVEN

:RESULTSEVEN
echo Question seven of ten
echo Your work station should NOT be:
if %aseven%==1 echo "Adequately ventilated" is wrong.
if %aseven%==1 echo Correct answer is 3, "Compact"
if %aseven%==2 echo "Well-organized" is wrong.
if %aseven%==2 echo Correct answer is 3, "Compact"
if %aseven%==3 echo "Compact" is correct.
if %aseven%==4 echo "Well-lit" is wrong.
if %aseven%==4 echo Correct answer is 3, "Compact"
pause
goto RESULTEIGHT

:RESULTEIGHT
echo Question eight of ten
echo What tool should you use to secure your work?
if %aeight%==1 echo "Wrench" is wrong.
if %aeight%==1 echo Correct answer is 3, "Vice"
if %aeight%==2 echo "Paper weight" is wrong.
if %aeight%==2 echo Correct answer is 3, "Vice"
if %aeight%==3 echo "Vice" is correct.
if %aeight%==4 echo "Your hand" is wrong.
if %aeight%==4 echo Correct answer is 3, "Vice"
pause
goto RESULTNINE

:RESULTNINE
echo Question nine of ten
echo What can you use to hold onto things like nails, screws, or chisels?
if %anine%==1 echo "Pocket" is wrong.
if %anine%==1 echo Correct answer is 2, "Hands"
if %anine%==2 echo "Hands" is correct.
if %anine%==3 echo "Mouth" is wrong.
if %anine%==3 echo Correct answer is 2, "Hands"
if %anine%==4 echo "All of the above" is wrong.
if %anine%==4 echo Correct answer is 2, "Hands"
pause
goto RESULTTEN

:RESULTTEN
echo Question ten of ten
echo Of the following only one action is acceptable. Select it.
if %aten%==1 echo "Using files without handles" is wrong.
if %aten%==1 echo Correct answer is 3, "Using clamps that are really big"
if %aten%==2 echo "Prying with a chisel" is wrong.
if %aten%==2 echo Correct answer is 3, "Using clamps that are really big"
if %aten%==3 echo "Using clamps that are really big" is correct.
if %aten%==4 echo "Hammering with a wrench" is wrong.
if %aten%==4 echo Correct answer is 3, "Using clamps that are really big""
pause
goto MAINMENU

:MARK
set mark= 0
if %aone%==2 set/a mark="%mark%+1"
if %atwo%==1 set/a mark="%mark%+1"
if %athree%==1 set/a mark="%mark%+1"
if %afour%==3 set/a mark="%mark%+1"
if %afive%==1 set/a mark="%mark%+1"
if %asix%==2 set/a mark="%mark%+1"
if %aseven%==3 set/a mark="%mark%+1"
if %aeight%==3 set/a mark="%mark%+1"
if %anine%==2 set/a mark="%mark%+1"
if %aten%==3 set/a mark="%mark%+1"
echo %mark%"/10" questions correct.
echo.
echo To see your answers, type 1
echo To go to the main menu, type 2
echo To exit the quiz, type 3
set/p markselection= Make your selection:
if %markselection%==1 goto RESULTONE
if %markselection%==2 goto MAINMENU
if %markselection%==3 goto ENDPROGRAM

:ACCREDITATION
cls
title Accreditation
echo -Information taken from Grade 9 shop question booklet
echo -Software used: Zed (available on chrome web store),
echo Notepad++ (available by google search),
echo Google drive and related services (available online)
echo -Creator: Exalor Stepaniuk (shop class grade censored, 2016/17)
echo.
pause
goto MAINMENU

:ENDPROGRAM
exit

再次,抱歉,如果我通过在此处转储整个脚本做错了什么。我只是不知道自己在做什么。

1 个答案:

答案 0 :(得分:1)

您的错误的根本原因是QUESTIONTEN中的这一行:

set/p athree=

这似乎是一个错字,因为您打算设置aten而不是athree

更具体地说,由于aten为空,在MARK内,比较最终会被解释为:

if ==3 set/a mark="[mark value]+1"

请注意左操作数为空。该行被解释错误,这就是您收到错误的原因。将athree更改为aten可以解决此问题,但有一种方法可以修复比较,以便在您的某个操作数为空时不会破坏脚本。只是在两边放东西。例如,用引号括住比较器。

if "%leftoperand%"=="%rightoperand%" ...

然后,即使其中一个或两个都是空的,它也不会终止你的脚本。它看起来就像if ""==""

此外,调试批处理文件的一般技巧是通过将echo语句(甚至是简单的语句,如echo 1)放在战略位置来缩小发生错误的位置(以及原因)。然后,当您在输出中看到1时,您知道该行已执行,并且您的错误在该行之后。一旦找到脚本终止的坏行,就可以回显它的副本以查看脚本将其解释为什么,这将帮助您找出问题。

像这样:

echo if %aten%==3 set/a mark="%mark%+1"
if %aten%==3 set/a mark="%mark%+1"

我希望有所帮助。