Page 1 of 1

~ Title bar Date & Clock help ~[ SOLVED ]

Posted: 29 Nov 2013 06:45
by Dos_Probie
Got this below code that sets the current day, date and (fixed) time to the title bar,
would like to have the clock active where the minute would change and not be fixed once
the batch menu stays up, any ideas on a easy way to accomplish this? Thanks for the help..DP

Code: Select all

@echo off
:: Output day, date and time to title bar..
set daydate=%date%
for /f "tokens=1,2" %%a in ('time/t') do set time12=%%a %%b
title, %daydate% @ %time12%
:menu
:<Rest of menu with code>
pause

Re: ~ Title bar Date & Clock help ~

Posted: 29 Nov 2013 08:44
by einstein1969
EDIT: Add auto-Sync to minute

Code: Select all

@echo off & setlocal EnableDelayedExpansion & goto :multithread_dispatcher

:Main 
  rem start timer sync to minute.
  start "" /B %0 timer_sync_to_minute set_title_date_time

:menu
  :<Rest of menu with code>
  pause
goto :eof


:: Functions/Subroutines ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:set_title_date_time
  :: Output day, date and time to title bar..
  set daydate=%date%
  for /f "tokens=1,2" %%a in ('time/t') do set time12=%%a %%b
  title, %daydate% @ %time12%
goto :eof

:multithread_dispatcher
  if not "%1"=="" (
      set label=%1
      shift
      goto :!label!
  )
goto :Main

:timer_sync_to_minute %1=function-subroutine
  rem first time call function
  call :%1
:loop_timer_sync_to_minute
  :: calulate the distance to next minute.
  for /F "tokens=1-4 delims=:.," %%a in ("%time: =0%") do set /a "a=(6000-(1%%c%%d-10000))*10"
  rem echo %time% distance to next minute in ms:%a% & rem for debugging
  :: if now are in the first 30 seconds then call function
  if %a% gtr 30000 (call :%1) else title Syncing... & rem remove else part if don't want debug syncing work
  :: wait until next minute
  ping 192.0.2.0 -w %a% -n 1 >nul
goto :loop_timer_sync_to_minute



Einstein1969

Re: ~ Title bar Date & Clock help ~

Posted: 29 Nov 2013 14:00
by Dos_Probie
Thanks for the Help Einstein! , the title clock lags about 20 sec behind the system clock (does not sync up) for some reason..DP

Re: ~ Title bar Date & Clock help ~

Posted: 29 Nov 2013 15:20
by einstein1969
Dos_Probie wrote:Thanks for the Help Einstein! , the title clock lags about 20 sec behind the system clock (does not sync up) for some reason..DP


because I not syncronize the timer with the clock.

can be solved with delayed start of the timer.

EDIT: I have edited the code of precedent post.

Einstein1969

Re: ~ Title bar Date & Clock help ~

Posted: 29 Nov 2013 16:22
by Dos_Probie
Einstein, the 1st code you posted showed the date and time in title but now your updated code is not working at all now.. must be a typo somewhere.

Re: ~ Title bar Date & Clock help ~

Posted: 29 Nov 2013 17:00
by AiroNG
Dos_Probie wrote:Einstein, the 1st code you posted showed the date and time in title but now your updated code is not working at all now.. must be a typo somewhere.


I just tried the posted code and it works. Just wait a few seconds.

Re: ~ Title bar Date & Clock help ~

Posted: 29 Nov 2013 17:04
by einstein1969
it works for me. :?

I have changed the set, try it now.

However, it takes up to a minute to display the first time because it has a delayed start. If you want see immediatly must add a call to the function.


Code: Select all

:Main
  rem calulate the delay (in seconds) for sync to minute.
  set /a "msec=(60-(1!time:~6,2!-100))*1000"

  rem start the timer delayed
  start "" /B %0 timer_delayed %msec% set_title_date_time 60000

  call :set_title_date_time

:menu
  :<Rest of menu with code>
  pause
goto :eof

Re: ~ Title bar Date & Clock help ~

Posted: 29 Nov 2013 17:09
by einstein1969
AiroNG wrote:
Dos_Probie wrote:Einstein, the 1st code you posted showed the date and time in title but now your updated code is not working at all now.. must be a typo somewhere.


I just tried the posted code and it works. Just wait a few seconds.


thanks for trying. However, I corrected the "set msec ..." because he had no double quotes. and have added e delayed time variable.

einstein1969

Re: ~ Title bar Date & Clock help ~

Posted: 29 Nov 2013 17:16
by AiroNG
thanks for trying. However, I corrected the "set msec ..." because he had no double quotes. and have added e delayed time variable.

Then i must have used the already edited code right before you answered.

Apologies Dos_Probie. My timing was bad.

Re: ~ Title bar Date & Clock help ~

Posted: 29 Nov 2013 17:21
by einstein1969
there is another problem. Now lag is one minute! :roll:

Re: ~ Title bar Date & Clock help ~

Posted: 29 Nov 2013 17:31
by einstein1969
I have added 2 second at the delayed start. One because of round error of hundredth of second and another for safety.

Code: Select all

  set /a "msec=(60-(1!time:~6,2!-100)+2)*1000"


I suppose it serves a function resynchronization timer ... :?

Einstein1969

Re: ~ Title bar Date & Clock help ~

Posted: 29 Nov 2013 20:10
by Dos_Probie
I reloaded your code and gives the path to my batch in title, until the min change then starts working..Will play around with it, just was hoping to get it to snyc right away like the post from Carlos and Aacini at: viewtopic.php?f=3&t=5028

Re: ~ Title bar Date & Clock help ~

Posted: 30 Nov 2013 09:04
by einstein1969
I have add auto resync to minute. Now is more precise and light. Try!

Einstein1969

Re: ~ Title bar Date & Clock help ~

Posted: 30 Nov 2013 19:12
by Dos_Probie
The auto sync did the trick, Thanks for all your Help, much appreciated!..DP :wink: