0

I'm creating a reminder which pops up a text file when a certain period of time passes and what I want to implement is a countdown (how many seconds and minutes are left until the upcoming loop begins). Everything seems to be going fine, until the part where I try to integrate minutes and seconds into one line. It gives me a "300 not expected here" error after the line echo Left (in minutes): %leftMinutes%. Any and all help would be appreciated.

Code

:Start
set /a wait = 0
set /a waitMinutes = 0
set /a left59 = %real_time% - 59 :: %real_time% is the inputed minutes,
                                 :: converted to seconds.
cls
color 0a
for /f "delims=" %%a in (Notes.txt) do (
set notes=%%a
)
cd %~dp0/Notes
start Notes.txt
goto Loop

:Loop
cls
echo Waiting for %answer_time% minutes.
echo.
set /a leftSeconds = %real_time% - %wait%
echo Left (in seconds): %leftSeconds%
set /a leftMinutes = %answer_time% - %waitMinutes%
echo Left (in minutes): %leftMinutes%
if %wait% LSS %left59% ( :: Checks if there's one more minute left in
                         :: %real_time%.
    if %wait% GEQ %left59% ( :: Checks if there's no more minutes left
                             :: in %real_time%.
        echo Left (both): %leftSeconds%
    )
    echo Left (both): %leftMinutes% and %leftSeconds%
)
timeout -t 1 -nobreak > nul
set /a wait += 1
if %wait% == 60 (
    set /a waitMinutes += 1
)
if not %wait% == %real_time% (
    goto Loop
)
if %wait% GEQ %real_time% (
    if %waitMinutes% == %answer_time% (
    taskkill -f -im Notepad.exe
    goto Start
    )
)

1 Answers1

1
  1. Never use :label nor :: label-like comment inside a command block enclosed in () parentheses; use REM instead of ::
  2. Escape all ) in echo commands. An unescaped closing parenthesis is still closing parenthesis even in echo.

For instance, instead of echo Left (both): %leftSeconds%, use

echo Left (both^): %leftSeconds%
rem            ^ note the caret

and, mutatis mutandis,

echo Left (both^): %leftMinutes% and %leftSeconds%
rem            ^ note the caret

Please read Syntax : Escape Characters, Delimiters and Quotes article.

Minimal changes (maybe incomplete) in your script are as follows:

if %wait% LSS %left59% ( REM Checks if there's one more minute left in
                         REM %real_time%.
    if %wait% GEQ %left59% ( REM Checks if there's no more minutes left
                             REM in %real_time%.
        echo Left (both^): %leftSeconds%
    )
    echo Left (both^): %leftMinutes% and %leftSeconds%
)
Community
  • 1
  • 1
JosefZ
  • 28,460
  • 5
  • 44
  • 83