当我输入5时,批处理文件退出并且什么都不做。我试图在if语句中运行脚本。但只有当你输入5时才会发生任何事情,所以我在问:为什么我的脚本在我5岁时不会运行if语句?
日Thnx
choice /c:12345 /n
if ERRORLEVEL 5 (
set snelheid=f5
goto tempsnelheid
)
if ERRORLEVEL 4 (
set snelheid=f4
goto tempsnelheid
)
if ERRORLEVEL 3 (
set snelheid=f3
goto tempsnelheid
)
if ERRORLEVEL 2 (
set snelheid=f2
goto tempsnelheid
)
if ERRORLEVEL 1 (
set snelheid=f1
goto tempsnelheid
)
:tempsnelheid
if "snelheid"=="f5" (
echo hoi
pause
)
答案 0 :(得分:2)
您正在比较字符串“snelheid”,而不是名为snelheid的变量的值。
所以
:tempsnelheid
if "snelheid"=="f5" (
echo hoi
pause
)
应该
:tempsnelheid
if %snelheid%=="f5" (
echo hoi
pause
)