Board logo

标题: [已解决] 关于计算字符串长度的批处理除BUG [打印本页]

作者: chishingchan     时间: 2008-4-17 10:04    标题: [已解决] 关于计算字符串长度的批处理除BUG

防沉迷系统中的一部分:时间设置

以下批处理流程:
1、输入使用次数;
2、输入时间段;
3、计算时间段长度。

但是得不到想要的结果,请各位朋友帮忙看一下,应如何修改。谢谢!
@echo off
:start
cls
set /p nth=请输入每天使用电脑的次数[1-5]:
if %nth% equ 0 cls&echo 没有限制,随意使用。&ping /n 3 127.1>nul&exit
if %nth% gtr 5 cls&echo 次数太多,返回重试!&ping /n 3 127.1>nul&goto start
:input
for /l %%i in (1,1,%nth%) do set /p nth%%i=请输入第 %%i 次使用时间段[xx:xx:xx-xx:xx:xx]:
call :length

:length
Setlocal EnableDelayedExpansion
set nth
for /l %%i in (1,1,!nth!) do for /l %%j in (1,1,20) do if "!nth%%i:~%%j,1!"=="" if %%j neq 17 cls&echo 时间段设置出错,返回重试。&ping /n 3 127.1>nul&cls&goto input
pause>nul
Endlocal
5楼正解

[ Last edited by chishingchan on 2008-11-23 at 12:01 ]
作者: moniuming     时间: 2008-4-17 21:03
call :length %%i
for /l %%i in (1,1,!nth!) do for /l %%j in (1,1,20) do if "!nth%1:~%%j,1!"=="" if %%j neq 17

[ Last edited by moniuming on 2008-4-17 at 10:15 PM ]
作者: chishingchan     时间: 2008-4-18 07:43    标题: 根据2楼的方案,还是不行。


@echo off
:start
cls
set /p nth=请输入每天使用电脑的次数[1-5]:
if %nth% equ 0 cls&echo 没有限制,随意使用。&ping /n 3 127.1>nul&exit
if %nth% gtr 5 cls&echo 次数太多,返回重试!&ping /n 3 127.1>nul&goto start
:input
for /l %%i in (1,1,%nth%) do set /p nth%%i=请输入第 %%i 次使用时间段[xx:xx:xx-xx:xx:xx]:
call :length %%i

:length
Setlocal EnableDelayedExpansion
set nth
for /l %%i in (1,1,!nth!) do for /l %%j in (1,1,20) do if "!nth%1:~%%j,1!"=="" if %%j neq 17 cls&echo 时间段设置出错,返回重试。&ping /n 3 127.1>nul&cls&goto input
pause>nul
Endlocal

作者: moniuming     时间: 2008-4-18 09:35
在这里用for是不合适的,容我想想
作者: moniuming     时间: 2008-4-18 09:58

@echo off
Setlocal enabledelayedexpansion
:start
cls
set /p nth=请输入每天使用电脑的次数[1-5]:
if %nth% equ 0 cls&echo 没有限制,随意使用。&ping -n 3 127.1>nul&exit
if %nth% gtr 5 cls&echo 次数太多,返回重试。&ping -n 3 127.1>nul&goto start
:input
if %nth%==0 goto :ok
set /a nth-=1
set /a times+=1
set /p time_=请输入第%times%次使用的时间段[xx:xx:xx-xx:xx:xx]:
for /l %%a in (1 1 20) do (
  if "!time_:~%%a,1!"=="" set aa=%%a&&if !aa! equ 17 (
    echo.&echo 这里是要执行的命令&ping -n 3 127.1>nul&goto :input
      ) else (
    set /a nth+=1&set /a times-=1&echo.&echo 时间段设置出错,返回重试。&ping -n 3 127.1>nul&goto :input
              )
)

:ok
echo.&echo 设置完毕。&ping -n 3 127.1>nul&goto :eof

作者: chishingchan     时间: 2008-4-18 14:18
谢谢!