标题: [代码合集] 做一个可以多选的菜单,一直报错求大佬苟命 [打印本页]
作者: guojiaqihs 时间: 2019-2-18 11:26 标题: 做一个可以多选的菜单,一直报错求大佬苟命
错误 1.此时不应有 4。
2.系统找不到文件 1。
鄙人纯合子小白,求各位大佬指点!- @echo off
- set /p str=enter the selected number:
-
- :STR_VISTOR
-
- echo str = %str%
-
- for /f "tokens=1,*" %%a in (%str%) do (
- set /a a=%%a
- set str="%%b"
- if %a% GTR 4 (
- echo nonscript
- ) else (
- echo script%a%
- goto script%a%
- )
- )
-
-
- :script1
- echo 1
- goto STR_VISTOR
-
- :script2
- echo 2
- goto STR_VISTOR
-
- : script3
- echo 3
- goto STR_VISTOR
-
- :script4
- echo 4
- goto STR_VISTOR
-
- :nonscript
- echo invalid number %%a
- goto STR_VISTOR
复制代码
作者: happyxxdhaha 时间: 2019-2-18 13:23
本帖最后由 happyxxdhaha 于 2019-2-18 13:24 编辑
- @echo off&setlocal enabledelayedexpansion
- set str=
- set /p str=enter the selected number:
-
- :STR_VISTOR
- if not defined str goto:eof
- echo str = %str%
-
- for /f "tokens=1,*" %%a in ("%str%") do (
- set a=%%a
- set str=%%b
- if !a! GTR 4 (
- echo nonscript
- goto:nonscript
- ) else (
- echo script!a!
- goto:script!a!
- )
- )
-
-
- :script1
- echo 1
- goto STR_VISTOR
-
- :script2
- echo 2
- goto STR_VISTOR
-
- :script3
- echo 3
- goto STR_VISTOR
-
- :script4
- echo 4
- goto STR_VISTOR
-
- :nonscript
- echo invalid number %a%
- goto STR_VISTOR
复制代码
作者: guojiaqihs 时间: 2019-2-18 13:59
回复 2# happyxxdhaha
真是非常非常非常感谢大佬了,苟命之恩!
作者: guojiaqihs 时间: 2019-2-19 09:24
回复 2# happyxxdhaha
不好意思,我想再请教一下。这个有什么简单的办法跳出循环吗?
我只能想到每个 script下加一句if "%%b"=="" (echo break loop)
作者: guojiaqihs 时间: 2019-2-19 10:30
天资愚钝,只能这样了。虽然ZZ但也算是能用了。- @echo off&setlocal enabledelayedexpansion
-
- echo
- set str=
- set /p str=enter the selected number:
- set str=%str% 999
- :STR_VISTOR
- if not defined str goto:eof
- for /f "tokens=1,*" %%a in ("%str%") do (
- set a=%%a
- set str=%%b
- if "%%b"=="" (goto:fin)
- if !a! GTR 4 (
- echo nonscript
- goto nonscript
- ) else (
- echo script!a!
- goto script!a!
- )
- )
-
-
-
- :script1
- echo 1
-
- goto STR_VISTOR
-
- :script2
- echo 2
-
- goto STR_VISTOR
-
- :script3
- echo 3
-
- goto STR_VISTOR
-
- :script4
- echo 4
-
- goto STR_VISTOR
-
- :nonscript
- echo invalid number %a%
-
- goto STR_VISTOR
-
- :fin
- echo 233
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |