下面的代码增加了键入检测:
1,检测键入字符是否合法。
2,增加容错,即允许重复键入,例如112,或1213,但重复的部分只执行一次。
3,10以内的代码,无论键入顺序如何,始终按照1到9执行。
@echo off
:s
cls&Endlocal
setlocal enabledelayedexpansion
set
set/p t=请输入1到3之间的数字任意组合,4为全部功能依次执行:
if %t%==4 set t=123
set m=%t%
for /l %%i in (1 1 3) do if not "!m!"=="" set "m=!m:%%i=!"
if not "%m%"=="" echo 输入错误&goto :e
:n
if not "!t:~%n%,1!"=="" set "han_!t:~%n%,1!=ye"&set/a n+=1&goto n
for /f "delims==" %%i in ('set^|find /i "han_"') do set t=%%i&set "s=!s! !t:~4!"
for %%i in (%s%) do call :%%i
:e:返回
echo 请按任意键重新开始
pause>nul
goto s
:1:功能1
echo 1
goto :eof
:2:功能2
echo 2
goto :eof
:3:功能3
echo 3
Last edited by Hanyeguxing on 2010-4-2 at 20:54 ]