Jump to content
Sign in to follow this  
anony10

Countdown problem

Recommended Posts

anony10

Hello!I want to make a shoutdown program.But when i try to do a count downer, it is counting in - (example: -1, -2, etc). So i need a little help, how to do it.Autoit just my hobby, so im so bad in it.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Sleep time!", 173, 212, 192, 124)
$Input1 = GUICtrlCreateInput("", 28, 40, 121, 21)
$Label1 = GUICtrlCreateLabel("T i m e :", 67, 13, 51, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label2 = GuiCtrlCreateLabel("asd", 80, 100, 51, 17)
$Button1 = GUICtrlCreateButton("Go!", 51, 141, 75, 25, 0)
$Button2 = GUICtrlCreateButton("Exit", 51, 172, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
   $read = GuiCtrlRead ($Input1)
   $time = $read * 60000
   Do
    $asd = GuiCtrlRead($label2)
    Sleep(1000)
    GuiCTrlSetData($label2, $asd -1)
   Until GuiCtrlRead($label2) = 0
   Sleep($time)
   msgbox(0, "asd", "asd")
  Case $Button2
   Exit
EndSwitch
WEnd

edit typo

Edited by anony10

Share this post


Link to post
Share on other sites
somdcomputerguy

Take a look at Time Machine #1. There's more in that thread, browse thru the whole thing, you might find something else useful.

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
anony10

Okay, thank you, but i didnt see anything useful.Okay theres some counters and itis good but i need count down.I cant do it, and i tryed to search on forum but nothing..

Share this post


Link to post
Share on other sites
JoHanatCent

Okay, thank you, but i didnt see anything useful.Okay theres some counters and itis good but i need count down.I cant do it, and i tryed to search on forum but nothing..

Try this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Sleep time!", 173, 212, 192, 124)
$Input1 = GUICtrlCreateInput("", 28, 40, 121, 21)
$Label1 = GUICtrlCreateLabel("T i m e :", 67, 13, 51, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("asd", 80, 100, 51, 17)
$Button1 = GUICtrlCreateButton("Go!", 51, 141, 75, 25, 0)
$Button2 = GUICtrlCreateButton("Exit", 51, 172, 75, 25, 0)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$read = GUICtrlRead($Input1)
$time = $read * 60000
GUICtrlSetData($Label2, $read);<<< ========== Add this?
Do
$asd = GUICtrlRead($Label2)
Sleep(1000)
GUICtrlSetData($Label2, $asd - 1)
Until GUICtrlRead($Label2) = 0
Sleep($time);<<<< ======== Do you want to sleep this long?
MsgBox(0, "asd", "asd")
Case $Button2
Exit
EndSwitch
WEnd

Share this post


Link to post
Share on other sites
anony10

Hm, it is good, but in input i write the minutes.and this is count like seconds.But thank you, i try to modifie it to minutes.

Share this post


Link to post
Share on other sites
anony10

Thank you, it is much better...But i need just a little help with this script!

#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
#Region ### START Koda GUI section ### Form=
Global $msg
Global $hGUI = GUICreate("Sleep time!", 173, 235, 192, 124)
Global $Input1 = GUICtrlCreateInput("Minutes", 28, 40, 121, 21)
Global $Label1 = GUICtrlCreateLabel("T i m e :", 67, 13, 51, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
Global $Label2 = GuiCtrlCreateLabel("Countdown", 49, 100, 90, 32)
Global $Label3 = GuiCtrlCreateLabel("The time is " & @HOUR & ":" & @MIN, 49, 120, 90, 32)
Global $Button1 = GUICtrlCreateButton("Go!", 51, 141, 75, 25, 0)
Global $Button2 = GUICtrlCreateButton("Exit", 51, 172, 75, 25, 0)
Global $Button3 = GuiCtrlCreateButton("Abort", 51, 201, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Do
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
  Case $Button1
   $inputread = GuiCtrlRead ($Input1)
   Global $countdown = $inputread ;minutes for countdown
   Global $seconds = $inputread * 60 ;convert to seconds
   Countdown()
   AdlibRegister("Countdown", 1000)
    EndSwitch
Until False
AdlibUnRegister("Countdown")
Exit
Func Countdown()
    Local $sec, $min, $hr
    $sec = Mod($seconds, 60)
    $min = Mod($seconds / 60, 60)
    $hr = Floor($seconds / 60 ^ 2)
    GUICtrlSetData($label2, StringFormat("%02i:%02i:%02i", $hr, $min, $sec))
    If $seconds <= 0 Then
        AdlibUnRegister("Countdown")
        MsgBox(0, "Information", "Countdown reached 00:00:00")
        Exit
    EndIf
    $seconds -= 1
EndFunc

Why under case $button1 $inputread doesnt work?

Share this post


Link to post
Share on other sites
anony10

And how can declare $inputread? Sorry im so newbie in it.

Share this post


Link to post
Share on other sites
UEZ

Try this:

#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
 
#Region ### START Koda GUI section ### Form=
Global $msg, $inputread, $countdown, $seconds
Global $hGUI = GUICreate("Sleep time!", 173, 235, 192, 124)
Global $Input1 = GUICtrlCreateInput("Minutes", 28, 40, 121, 21)
Global $Label1 = GUICtrlCreateLabel("T i m e :", 67, 13, 51, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
Global $Label2 = GuiCtrlCreateLabel("Countdown", 49, 100, 90, 32)
Global $Label3 = GuiCtrlCreateLabel("The time is " & @HOUR & ":" & @MIN, 49, 120, 90, 32)
Global $Button1 = GUICtrlCreateButton("Go!", 51, 141, 75, 25, 0)
Global $Button2 = GUICtrlCreateButton("Exit", 51, 172, 75, 25, 0)
Global $Button3 = GuiCtrlCreateButton("Abort", 51, 201, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Do
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            AdlibUnRegister("Countdown")
            Exit
        Case $Button1
           $inputread = GuiCtrlRead ($Input1)
           $countdown = $inputread ;minutes for countdown
           $seconds = $inputread * 60 ;convert to seconds
           Countdown()
           AdlibRegister("Countdown", 1000)
    EndSwitch
Until False
 
Func Countdown()
    Local $sec, $min, $hr
    $sec = Mod($seconds, 60)
    $min = Mod($seconds / 60, 60)
    $hr = Floor($seconds / 60 ^ 2)
    GUICtrlSetData($label2, StringFormat("%02i:%02i:%02i", $hr, $min, $sec))
    If $seconds <= 0 Then
        AdlibUnRegister("Countdown")
        MsgBox(0, "Information", "Countdown reached 00:00:00")
        Exit
    EndIf
    $seconds -= 1
EndFunc

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×