所以我在做一个计数器,但我不知道该怎么做..我现在有一些用于定制的其他函数:
set /a current_value=current_value+incremental_value
但不幸的是它不能工作..整个目的是使用pause >nul
功能,这样当用户按下某个键时,屏幕将显示一个数字,按前面选择的增量值递增。
这是整个脚本:
@echo off
cls
title Counter
:Incremental_Value
cls
echo./----------------------------------------------\
echo.I Set the Incremental Value then press Enter I
echo.\----------------------------------------------/
echo.
set /p %incremental_value%= [
:Starter_Value
cls
set current_value=%starter_value%
echo./------------------------------------------\
echo.I Set the Starter Value then press Enter I
echo.\------------------------------------------/
echo.
set /p %starter_value%= [
goto Counter
:Counter
cls
echo./-------------------\
echo.I %current_value% I
echo.\-------------------/
echo.
pause >nul
set /a current_value=current_value+incremental_value
goto Counter
编辑:我修复了关机的问题,但当你第一次进入柜台屏幕时,数字不会出现。一旦你点击了一个键,它就变成了零(如果你将起始值设置为零),那么如果你继续按键,它就不会增加增量值。
发布于 2019-01-03 14:30:20
您遇到的一个非常简单的问题是不正确地使用set /p
命令。使用set /p
时,不要将字符串指定为set /p %String%=
,而应指定为set /p String=
。有关set命令的更多信息,请尝试在命令提示符中键入set /?
。
另一个问题,不是问题是你有:Incremental_Value
& :Starter_Value
,但是你从来没有在脚本中使用call
或者goto
。唯一能正确做到这一点的地方是goto Counter
。除非您打算稍后单独对它们执行goto
/call
操作,否则只需删除它们;或者使用goto :Starter_Value
- exc。
将来,尝试使用echo(
而不是echo.
来调用窗口中的空白。
Counter.bat
@echo off
title Counter With Incremental Progression
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Set the Starter Value then press Enter º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo(
set /p starter_value=Value:
cls
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Set the Incremental Value then press Enter º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo(
set /p incremental_value=Value:
Set "current_value=%starter_value%"
:Counter
cls
echo Current Number: %current_value%
echo(
pause >nul
set /a "current_value=current_value+incremental_value"
goto Counter
PS:将文件编码切换为ANSI
,用于fun boxes :-)
https://stackoverflow.com/questions/54016437
复制相似问题