Giovanni Barberio
Giovanni Barberio

Reputation: 5

Batch counter program shutting down

So I am making a counter and I am not sure how to make it work.. I have this right now with some other functions for customization purposes:

set /a current_value=current_value+incremental_value

but it does not work unfortunately.. The whole purpose is to use the pause >nul function so when ever the user presses a key then the screen will show a number go up by the incremental value chosen earlier..

This is the whole script:

@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

Edit: I fixed the shutting down problem, but when you first get to the Counter screen the number does not appear. Once you hit a key it becomes zero (if you set the starting value to zero) then it wont add the incremental value if you continue to press the key.

Upvotes: 0

Views: 172

Answers (1)

John Kens
John Kens

Reputation: 1679

A very simple issue you had was the improper use of the set /p command. When using set /p, you do not specify the string as set /p %String%= but rather set /p String=. For more information on the set command try typing set /? into a command prompt.

Another issue, not problem is that you have :Incremental_Value & :Starter_Value but you never call or goto them in the script. The only place you properly did this was with goto Counter. Unless you are going to individually goto/call them later, just remove them; or use goto :Starter_Value - exc.

In the future, try using echo( instead of echo. to call a blank space in the window.

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: Switch the file encoding to ANSI for fun boxes - :-)

Upvotes: 2

Related Questions