Problems in batch droplet

Asked

Viewed 110 times

1

I am beginner in batch And I’m trying to create a very simple alarm clock program. The user must set the time you want the alarm clock to ring and the program will check the time of the computer. If the time is the same as set, the program will print "BEEP!". This is my code:

@echo off

set /p %tempoDefinido%=Defina um tempo para o alarme: 

:wait
if %time:~0,8% equ %tempoDefinido% (echo BEEP!) else (goto wait)
pause

The problem here is that the program does not go back to the :wait. It just goes on until the pause and close. What I’m doing wrong ?

2 answers

2


Your error was that you did not set the %time variable. No percentage is used when setting the variable only when checking its contents. When IF happens it compares an existing variable "%temp% with a non-existent variable %timeDefined% this causes an error causing if to be ignored and goes straight to pause.

So instead of:

set /p %tempoDefinido%=Defina um tempo para o alarme: 

Use:

set /p tempoDefinido=Defina um tempo para o alarme: 

Consider doing something like this:

@echo off

set /p tempoDefinido=Defina um tempo para o alarme: 

:wait
cls
echo.
echo Hora atual: %time:~0,8% Alarme: %tempoDefinido%
if %time:~0,8% equ %tempoDefinido% (echo BEEP!) else (timeout /t 1 > nul & goto wait)

echo.
pause

inserir a descrição da imagem aqui

  • I had forgotten that detail, thank you very much. It worked here <3

1

Some options to sound the alarm:


@echo off & setlocal enabledelayedexpansion & cls & title nul & title Alarme^!!

echo/ & set /p "alarme= [!time:~0,-6!] Defina um tempo para o alarme : "

:wait
echo/!time:~0,-6! | findstr /bl !alarme! >nul || goto :wait 
for /f %%i in ('forfiles /m "%~nx0" /c "cmd /c echo/0x07"')do echo/ & echo/ Hora certa: !time:~,8! ^| Beep^^!! %%i
>nul %__appdir__%pathping.exe 127.1 -n -q 1 -p 600 & %__appdir__%rundll32.exe %__appdir__%cmdext.dll,MessageBeepStub
>nul %__appdir__%pathping.exe 127.1 -n -q 1 -p 600 & %__appdir__%timeout -t -01 & endlocal & exit /b

  • Thanks, this will be useful in the future but for now I don’t even know how to use the "for" kkkk.

  • @Jeanextreme002 with more time in the sequence I will put a descriptive on the action of the for!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.