Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Countdown in MsgBox


  • Please log in to reply
20 replies to this topic
Marc
  • Guests
  • Last active:
  • Joined: --
Hello,

I would like to have a countdown in my MassageBox that indicates the remaining time until timeout.

The code just starts my calendar, so its not very important, just curiosity.

MsgBox, 292, Kalender?, Soll der Kalender gestartet werden?, 5

IfMsgBox Yes
	Run, C:\Program Files (x86)\Rainlendar2\Rainlendar2.exe, C:\Program Files (x86)\Rainlendar2.
else
ExitApp

Thanks
Marc

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Secs := 20
SetTimer, CountDown, 1000
MsgBox, 1, System Shutdown in 20 seconds, Allow Auto Shutdown?, %Secs%
SetTimer, CountDown, Off

/*
IfMsgBox Ok
  Shutdown, 8
*/
 
   
Return


CountDown:
Secs -= 1
WinSetTitle, System Shutdown in,, System Shutdown in %Secs% seconds 
Return

:)

Marc
  • Guests
  • Last active:
  • Joined: --
Thats it, Thanks a lot! :D

Mustang
  • Members
  • 421 posts
  • Last active: Dec 26 2010 10:08 PM
  • Joined: 17 May 2007
I could do with a MassageBox

Murp-e
  • Members
  • 531 posts
  • Last active: Sep 27 2011 11:44 AM
  • Joined: 12 Jan 2007
Although a massagebox sounds great, if you don't want to use the WinSetTitle method provided, you could use a simple GUI instead of the massagebox. In which case you would replace WinSetTitle with controlsettext.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

Although a massagebox sounds great, if you don't want to use the WinSetTitle method provided, you could use a simple GUI instead of the massagebox. In which case you would replace WinSetTitle with controlsettext.

It works on a MsgBox as well :)
Secs := 20
SetTimer, CountDown, 1000
MsgBox, 1, System Shutdown, Allow Auto Shutdown in %Secs%?, %Secs%
SetTimer, CountDown, Off
/*
IfMsgBox Ok
  Shutdown, 8
*/
Return

CountDown:
Secs -= 1
ControlSetText,Static1,Allow Auto Shutdown in %Secs%?,System Shutdown ahk_class #32770
Return


Murp-e
  • Members
  • 531 posts
  • Last active: Sep 27 2011 11:44 AM
  • Joined: 12 Jan 2007
HotKeyIt: Thanks for clarifying that -and it only took you about 10 months!

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
:lol:

  • Guests
  • Last active:
  • Joined: --
Thanks to posts above i managed to make countdown in a ToolTip :p
Still figuring out how to tweak it to show 0 as last number, not 1...

sec:=170
ToolTip, %sec% seconds remaining.
SetTimer, RemoveToolTip, 1000
return

RemoveToolTip:
sec -=1
if %sec% >= 0 
{
SetTimer,RemoveToolTip,Off
ToolTip
return
}
else
ToolTip, %sec% seconds remaining.
return


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Still figuring out how to tweak it to show 0 as last number, not 1...


Use
if ( sec < 0 )
Instead of
if %sec% >= 0


None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
Do you want it formated as minutes and seconds
#Persistent
sec:=170
SetTimer, RemoveToolTip, 1000 

RemoveToolTip: 
ToolTip, % (Sec--<1) ? "" : FormatSeconds(sec) " seconds remaining."
If (Sec<0)
 SetTimer, RemoveToolTip, Off
return 

FormatSeconds(x) 
{ 
Out:=SubStr("0" . Mod(x, 60),-1),x:=Floor(x/60)
Return x ":" Out
}
Mostly just showing off :wink:

  • Guests
  • Last active:
  • Joined: --
Awesome, thank you very much :]

  • Guests
  • Last active:
  • Joined: --
Again me with my ToolTip :p

The above code is missing else statment in order to make it proceed with code after timer countdown ends.

I have small issue: i cant loop the code, error pops up at line 45 "a RETURN must be encountered prior to this } "

Loop 20 { 
MouseClick, left,  253,  598
Sleep, 1500
MouseClick, left,  134,  358
Sleep, 1500
MouseClick, left,  128,  246
Sleep, 1500
MouseClick, left,  200,  420
Sleep, 1500
Send, {ESC}
MouseClick, left,  24,  57
MouseClick, left,  24,  57
Sleep, 1500
MouseClick, left,  155,  192
Sleep, 1500
MouseClick, left,  265,  428
#Persistent
sec:=170
SetTimer, RemoveToolTip, 1000
RemoveToolTip:
ToolTip, % (Sec--<1) ? "" : FormatSeconds(sec) " seconds remaining."
If (Sec<0)
 SetTimer, RemoveToolTip, Off
else
 Return
FormatSeconds(x)
{
Out:=SubStr("0" . Mod(x, 60),-1),x:=Floor(x/60)
Return x ":" Out
}
Send, {ESC}
MouseClick, left,  253,  607
Sleep, 1500
MouseClick, left,  151,  353
Sleep, 1500
MouseClick, left,  144,  252
Sleep, 1500
MouseClick, left,  202,  420
Sleep, 1500
Send, {ESC}
}

I don't really see why it demands a return command, code that is being Loop'ed must be in {} and so it is, but i get that error.

None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
So you want the whole thing to loop 20 times but you want it to wait 170 seconds in the middle with some indication of how much time is left?
Loop 20 { 

MouseClick, left,  253,  598 

Sleep, 1500 

MouseClick, left,  134,  358 

Sleep, 1500 

MouseClick, left,  128,  246 

Sleep, 1500 

MouseClick, left,  200,  420 

Sleep, 1500 

Send, {ESC} 

MouseClick, left,  24,  57 

MouseClick, left,  24,  57 

Sleep, 1500 

MouseClick, left,  155,  192 

Sleep, 1500 

MouseClick, left,  265,  428



sec:=170

While !(Sec<0) { ;wait the number of seconds then continue

 ToolTip, % (Sec--<1) ? "" : FormatSeconds(sec) " seconds remaining." 

 Sleep 1000

 }



Send, {ESC} 

MouseClick, left,  253,  607 

Sleep, 1500 

MouseClick, left,  151,  353 

Sleep, 1500 

MouseClick, left,  144,  252 

Sleep, 1500 

MouseClick, left,  202,  420 

Sleep, 1500 

Send, {ESC} 

}



FormatSeconds(x) ;function can be at the end

{ 

Out:=SubStr("0" . Mod(x, 60),-1),x:=Floor(x/60) 

Return x ":" Out 

}


  • Guests
  • Last active:
  • Joined: --
Exactly that's what i wanted to do.

But... i know it works using WHILE, could you explain me the error i am reciving?

Im really breaking my mind at this, why it demands return? Where is a bug in my code?

It's killing me :[