解决方案:
@ECHO off &SETLOCAL EnableDelayedExpansion
:vars
SET "fC=a"
SET "sC=b"
SET "toEcho="
PAUSE
FOR /L %%f IN (1, 1, 3) DO (
IF %%f == 1 SET "toEcho=!toEcho!%fC%"
IF %%f == 2 SET "toEcho=!toEcho!%fC%"
IF %%f == 3 SET "toEcho=!toEcho!%fC%"
)
FOR /L %%f IN (4, 1, 6) DO (
IF %%f == 4 SET "toEcho=!toEcho!%sC%"
IF %%f == 5 SET "toEcho=!toEcho!%sC%"
IF %%f == 6 SET "toEcho=!toEcho!%sC%"
)
ECHO %toEcho%
GOTO end
:end
PAUSE
真正的项目是一个酒吧。我将完成级别的百分比作为参数提供给标签,这对我来说是一个完整的加载栏!
第一个参数是多大的酒吧必须是信息。
:bar size loaded
CLS
SET /A "toDo=(%~1*%~2)/100"
SET /A "remains=%~1-%toDo%"
ECHO %~2%%
SET "bar_up=%corUL%"
FOR /L %%i IN (1, 1, %~1) DO SET "bar_up=!bar_up!%linHo%"
SET "bar_up=!bar_up!%corUR%
ECHO %bar_up%
SET "bar_ce=%linVe%"
FOR /L %%i IN (1, 1, %toDo%) DO SET "bar_ce=!bar_ce!%barDo%"
FOR /L %%i IN (1, 1, %remains%) DO SET "bar_ce=!bar_ce!%barSp%"
SET "bar_ce=!bar_ce!%linVe%
ECHO %bar_ce%
SET "bar_do=%corDL%"
FOR /L %%i IN (1, 1, %~1) DO SET "bar_do=!bar_do!%linHo%"
SET "bar_do=!bar_do!%corDR%
ECHO %bar_do%
EXIT /B
其他变量是:
corUL = 左上角字符
corUR = 右上角字符
corDL = 左下角字符
corDR = 右下角字符
linHo = 水平线字符
linVe = 竖线字符
barDo = 指示条的完成部分的字符
barSp = 指示条的空白部分的字符