Issues with my progress bar

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Dasmius
Posts: 21
Joined: 02 Mar 2022 13:47

Issues with my progress bar

#1 Post by Dasmius » 16 Jan 2023 12:13

I've implemented an progress bar to my code to each block of comands, but when i starts the next block, the progress bar doesn't reset to 0 and starts to count and fill again even if I set percent=0

CLS
ECHO.
ECHO [92mBLOCK 1...[0m

::Operations with progress bar
set /a max=10
set n=0
for /L %%i in (1,1,%max%) do set /A n+=1

set /a lengthbar=100
set "bar="
for /L %%i in (1,1,%lengthbar%) do set "bar=!bar!█"
set "space="
for /L %%i in (1,1,%lengthbar%) do set "space=!space!_"

set i=0
echo [92mProcessando:[0m
for /L %%i in (1,1,%max%) do (
set /A i+=1, percent=!i!*%lengthbar%/!n!
for %%a in (!percent!) do (
set bar2=!bar:~0,%%a!
set /a left=%lengthbar%-%%a
for %%b in (!left!) do (
set space2=!space:~-%%b!
ECHO [1;1H
ECHO.
ECHO.
ECHO Progress: %%a%% !bar2!!space2!
)
)

REM Code goes here

ping -n 2 127.0.0.1 > nul
)

CLS
ECHO.
ECHO [92mBLOCK 2...[0m
set /A i+=1, percent=!i!*%lengthbar%/!n!
for %%a in (!percent!) do (
set bar2=!bar:~0,%%a!
set /a left=%lengthbar%-%%a
for %%b in (!left!) do (
set space2=!space:~-%%b!
ECHO [1;1H
ECHO.
ECHO.
ECHO Progress: %%a%% !bar2!!space2!
)
)

REM Code goes here

ping -n 2 127.0.0.1 > nul
)

REM CODE HERE


ping -n 2 127.0.0.1 > nul
)

repeat again

AGAIN

Again

even if I:
Set percent=0
set i=0
set n=0

before starts the new block, it doesn't work, just shows progressbar =0 and unfilled

Can you guys help me?

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Issues with my progress bar

#2 Post by Compo » 16 Jan 2023 20:25

It's not going to be easy to help you when you only post some of your code! In addition to that, the code you have posted is invalid, because it has more closing parentheses than it does opening ones. This may suggest that what you have posted is already nested or subnested within other code blocks too.

Please edit your qiestion to update the code, and this time please enclose it within code blocks.

Dasmius
Posts: 21
Joined: 02 Mar 2022 13:47

Re: Issues with my progress bar

#3 Post by Dasmius » 19 Jan 2023 11:01

Updating

I tried this, but no sucess:

@ECHO OFF

MODE CON: COLS=150 LINES=50

CHCP 65001

REM.-- Preparando processador de comandos
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

ECHO.
ECHO [92mCriando Estruturas de pastas...[0m
::Operations with progress bar
::Operations with progress bar
set /a max=10
set n=0
for /L %%i in (1,1,%max%) do set /A n+=1

set /a lengthbar=100
set "bar="
for /L %%i in (1,1,%lengthbar%) do set "bar=!bar!█"
set "space="
for /L %%i in (1,1,%lengthbar%) do set "space=!space!_"

set i=0
echo [92mProcessando:[0m
for /L %%i in (1,1,%max%) do (
set /A i+=1, percent=!i!*%lengthbar%/!n!
for %%a in (!percent!) do (
set bar2=!bar:~0,%%a!
set /a left=%lengthbar%-%%a
for %%b in (!left!) do (
set space2=!space:~-%%b!
ECHO [1;1H
ECHO.
ECHO.
ECHO Progress: %%a%% !bar2!!space2!
)
)

REM CODE HERE

ping -n 2 127.0.0.1 > nul
)
CLS
ECHO.
ECHO [92mImplementando Avaya Agent, aguarde...[0m
set /a max1=10
set n1=0
for /L %%i in (1,1,%max%) do set /A n1+=1

set /a lengthbar1=100
set "bar1="
for /L %%i in (1,1,%lengthbar1%) do set "bar1=!bar!█"
set "space1="
for /L %%i in (1,1,%lengthbar1%) do set "space1=!space1!_"

set i1=0
echo [92mProcessando:[0m
for /L %%i in (1,1,%max1%) do (
set /A i1+=1, percent1=!i!*%lengthbar1%/!n1!
for %%a in (!percent1!) do (
set bar3=!bar1:~0,%%a!
set /a left1=%lengthbar1%-%%a
for %%b in (!left1!) do (
set space3=!space1:~-%%b!
ECHO [1;1H
ECHO.
ECHO.
ECHO Progress: %%a%% !bar3!!space3!
)
)

REM CODE HERE

)
CLS
ECHO.

:: it just follow repepeating and increasing....

Well Can I say that it doesn't worked.. The first Block finish at 100% (at leat I think it do cause when reachs 90% in the next second comes de CLS and appears as showed at secont block of commands....

Página de código ativa: 65001

Criando Estruturas de pastas...
Progress: 90% ██████████████████████████████████████████████████████████████████████████████████████____________



and the second do not starts another bar count and fill as it just appears like that:

Implementando Avaya Agent, aguarde...
Processando:
Progress: 100% ████████████████████████████████████████████████████████████████████████████████████████████████████____________________________________________________________________________________________________



Any idea about how to do it works?

Lucky4Me
Posts: 24
Joined: 21 Oct 2020 06:33

Re: Issues with my progress bar

#4 Post by Lucky4Me » 20 Jan 2023 10:36

Make sure that all your variables are set correct and used correct!

Code: Select all

@ECHO OFF

MODE CON: COLS=150 LINES=50

CHCP 65001

REM.-- Preparando processador de comandos
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

ECHO.
ECHO [92mCriando Estruturas de pastas...[0m
::Operations with progress bar
::Operations with progress bar
set /a max=10
set n=0
for /L %%i in (1,1,%max%) do set /A n+=1

set /a lengthbar=100
set "bar="
for /L %%i in (1,1,%lengthbar%) do set "bar=!bar!█"
set "space="
for /L %%i in (1,1,%lengthbar%) do set "space=!space!░"

set i=0
echo [92mProcessando:[0m
for /L %%i in (1,1,%max%) do (
set /A i+=1, percent=!i!*%lengthbar%/!n!
for %%a in (!percent!) do (
set bar2=!bar:~0,%%a!
set /a left=%lengthbar%-%%a
for %%b in (!left!) do (
set space2=!space:~-%%b!
ECHO [1;1H
ECHO.
ECHO.
ECHO Progress: %%a%% !bar2!!space2!
)
)

REM CODE HERE

ping -n 2 127.0.0.1 > nul
)
CLS
ECHO.
ECHO [92mImplementando Avaya Agent, aguarde...[0m
set /a max1=10
set n1=0
for /L %%i in (1,1,%max%) do set /A n1+=1

set /a lengthbar1=100
set "bar1="
for /L %%i in (1,1,%lengthbar1%) do set "bar1=!bar!█"
set "space1="
for /L %%i in (1,1,%lengthbar1%) do set "space1=!space1!░"

set i1=0
echo [92mProcessando:[0m
for /L %%i in (1,1,%max1%) do (
set /A i1+=1, percent1=!i1!*%lengthbar1%/!n1!
for %%a in (!percent1!) do (
set bar3=!bar1:~0,%%a!
set /a left1=%lengthbar1%-%%a
for %%b in (!left1!) do (
set space3=!space1:~-%%b!
ECHO [1;1H
ECHO.
ECHO.
ECHO Progress: %%a%% !bar3!!space3!
)
)

REM CODE HERE
ping -n 2 127.0.0.1 > nul
)
CLS
ECHO.
your i1 wasn't working in set /A i1+=1, percent1=!i!*%lengthbar1%/!n1!

Post Reply