我试图运行一个从60:00倒计时的脚本,其中60是秒数,00是毫秒数。我无法让脚本正常运行。任何人都知道问题是什么?
:PhaseTwo
Set /a bignum=60
Set smallnum=00
Set /a handlevariable=1
Set /a bignumhandle=0
ping localhost -n 2 >nul
:StopWatchRoutine
If %bignum% EQU 00 GoTo :StopWatchEndCheck
:StopWatchEndCheckNo
If %bignum% EQU 9 set /a bignumhandle=1
If %smallnum% EQU 9 set /a handlevariable=1
If %handlevariable% EQU 1 GoTo :NumberMods
Set /a smallnum-=1
GoTo :StopWatchHandle
:StopWatchEndCheck
If %smallnum% EQU 01 GoTo :StopWatchExit
GoTo :StopWatchEndCheckNo
:NumberMods
If %smallnum% EQU 00 set /a smallnum=99
If %smallnum% EQU 00 set /a handlevariable=0
If %smallnum% EQU 01 set smallnum=00
If %smallnum% EQU 02 set smallnum=01
If %smallnum% EQU 03 set smallnum=02
If %smallnum% EQU 04 set smallnum=03
If %smallnum% EQU 05 set smallnum=04
If %smallnum% EQU 06 set smallnum=05
If %smallnum% EQU 07 set smallnum=06
If %smallnum% EQU 08 set smallnum=07
If %smallnum% EQU 09 set smallnum=08
If %smallnum% EQU 9 set smallnum=09
If %smallnum% EQU 99 set /a bignum-=1
If %bignumhandle% EQU 1 GoTo :BigNumMods
GoTo :StopWatchHandle
:BigNumMods
If %bignum% EQU 01 set bignum=00
If %bignum% EQU 02 set bignum=01
If %bignum% EQU 03 set bignum=02
If %bignum% EQU 04 set bignum=03
If %bignum% EQU 05 set bignum=04
If %bignum% EQU 06 set bignum=05
If %bignum% EQU 07 set bignum=06
If %bignum% EQU 08 set bignum=07
If %bignum% EQU 09 set bignum=08
If %bignum% EQU 9 set bignum=09
:StopWatchHandle
cls
echo Program Launch Console, Version 1.0.2
echo.
echo StopWatch: %bignum%:%smallnum%
echo.
ping localhost -n 1 >nul
GoTo :StopWatchRoutine
:StopWatchExit
echo.
GoTo :PhaseThree
我使用此批处理文件作为用户界面的一部分,因此重要的是它的回声部分保持不变。否则,欢迎任何有关如何提高脚本效率的建议。
感谢您的所有帮助,非常非常感谢。
答案 0 :(得分:0)
对不起。首先评论一下:
ping
命令?它的效果恰恰与所期望的相反!无论如何,如果你想在Batch中有一个更有效的倒计时例程,试试这个:
@echo off
setlocal EnableDelayedExpansion
:PhaseTwo
rem Get a CR control character (Ascii 13)
for /F %%a in ('copy /Z "%~F0" nul') do set "CR=%%a"
cls
echo Program Launch Console, Version 1.0.2
echo.
set /P "=StopWatch: 60.000!CR!" < NUL
set /A bignum=60, smallnum=2000
for /F "tokens=3 delims=:." %%a in ("%time%") do set "currentSec=%%a"
:StopWatchRoutine
for /F "tokens=3 delims=:." %%a in ("%time%") do if "%currentSec%" equ "%%a" (
set /A smallnum-=4
) else (
rem The next line will help to adjust previous smallnum's subtrahend
REM ECHO/
set "currentSec=%%a"
set /A bignum-=1, smallnum=2000
if !bignum! equ 0 goto StopWatchExit
)
:StopWatchHandle
set /P "=StopWatch: %bignum%:%smallnum:~1% !CR!" < NUL
GoTo :StopWatchRoutine
:StopWatchExit
echo StopWatch: 0.000
echo/
echo.
请注意,为了以尽可能真实的方式显示毫秒,您必须在set /A smallnum-=4
命令中调整数字。 &#34; 4&#34;是我的电脑的正确选择。