Jump to content

Recommended Posts

  • Moderators
Posted

FSoft,

Here you go. Use _TimeToTicks to get a tick value for your alarm time and then compare that value to the instantaneous _TimeToTicks value.

As an added bonus, I have given you inputs that are limited to 2 characters, move automatically to the next when full, and have some errorchecking for the values entered by the user. No extra charge!

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Date.au3>

GUICreate("Timer Test", 200, 200)

$label2 = GUICtrlCreateLabel("",20,20,100,20)
GUICtrlSetState(-1, $GUI_HIDE)
$button = GUICtrlCreateButton("Start", 20, 100, 80, 30)
$hour = GUICtrlCreateInput("",20,150,20,20)
GUICtrlSetLimit(-1, 2)
$min = GUICtrlCreateInput("",50,150,20,20)
GUICtrlSetLimit(-1, 2)
$sec = GUICtrlCreateInput("",80,150,20,20)
GUICtrlSetLimit(-1, 2)

GUISetState()

GUIRegisterMsg($WM_COMMAND, "On_WM_COMMAND")

$fTimer = False
Global $EndTicks = 0
$begin = TimerInit()

While 1
    
    Select
        Case TimerDiff($begin) > 1000
            GUICtrlSetData($label2,@HOUR&":"&@MIN&":"&@SEC)
            $begin = TimerInit()
        Case _TimeToTicks(@HOUR,@MIN,@SEC) = $EndTicks
            GUICtrlSetData($button, "Start")
            GUICtrlSetState($label2, $GUI_HIDE)
            For $i = $hour To $sec
                GUICtrlSetData($i, "")
            Next
            MsgBox(0, "Timer test", "Ding!")
    EndSelect
    
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
            $fTimer = Not $fTimer
            If $fTimer Then
                GUICtrlSetData($button, "Stop")
                GUICtrlSetState($label2, $GUI_SHOW)
                Set_Alarm()
            Else
                GUICtrlSetData($button, "Start")
                GUICtrlSetState($label2, $GUI_HIDE)
            EndIf
    EndSwitch
    
WEnd

Func Set_Alarm()
    $Alarm_Hour = GUICtrlRead($hour)
    If $Alarm_Hour > 23 Or $Alarm_Hour = "" Then
        $Alarm_Hour = 0
        GUICtrlSetData($hour, "00")
    EndIf
    $Alarm_Min = GUICtrlRead($min)
    If $Alarm_Min > 59 Or $Alarm_Min = "" Then
        $Alarm_Min = 0
        GUICtrlSetData($min, "00")
    EndIf
    $Alarm_Sec = GUICtrlRead($sec)
    If $Alarm_Sec > 59 Or $Alarm_Sec = "" Then
        $Alarm_Sec = 0
        GUICtrlSetData($sec, "00")
    EndIf
    $EndTicks = _TimeToTicks($Alarm_Hour, $Alarm_Min, $Alarm_Sec)
EndFunc

Func On_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAnd($wParam, 0x0000FFFF)
    Switch $nNotifyCode
        Case 0x400;$EN_UPDATE
            If StringLen(GUICtrlRead($nID)) = 2 Then GUICtrlSetState($nID+1, $GUI_FOCUS)
    EndSwitch
EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

FSoft,

Here you go. Use _TimeToTicks to get a tick value for your alarm time and then compare that value to the instantaneous _TimeToTicks value.

As an added bonus, I have given you inputs that are limited to 2 characters, move automatically to the next when full, and have some errorchecking for the values entered by the user. No extra charge!

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Date.au3>

GUICreate("Timer Test", 200, 200)

$label2 = GUICtrlCreateLabel("",20,20,100,20)
GUICtrlSetState(-1, $GUI_HIDE)
$button = GUICtrlCreateButton("Start", 20, 100, 80, 30)
$hour = GUICtrlCreateInput("",20,150,20,20)
GUICtrlSetLimit(-1, 2)
$min = GUICtrlCreateInput("",50,150,20,20)
GUICtrlSetLimit(-1, 2)
$sec = GUICtrlCreateInput("",80,150,20,20)
GUICtrlSetLimit(-1, 2)

GUISetState()

GUIRegisterMsg($WM_COMMAND, "On_WM_COMMAND")

$fTimer = False
Global $EndTicks = 0
$begin = TimerInit()

While 1
    
    Select
        Case TimerDiff($begin) > 1000
            GUICtrlSetData($label2,@HOUR&":"&@MIN&":"&@SEC)
            $begin = TimerInit()
        Case _TimeToTicks(@HOUR,@MIN,@SEC) = $EndTicks
            GUICtrlSetData($button, "Start")
            GUICtrlSetState($label2, $GUI_HIDE)
            For $i = $hour To $sec
                GUICtrlSetData($i, "")
            Next
            MsgBox(0, "Timer test", "Ding!")
    EndSelect
    
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
            $fTimer = Not $fTimer
            If $fTimer Then
                GUICtrlSetData($button, "Stop")
                GUICtrlSetState($label2, $GUI_SHOW)
                Set_Alarm()
            Else
                GUICtrlSetData($button, "Start")
                GUICtrlSetState($label2, $GUI_HIDE)
            EndIf
    EndSwitch
    
WEnd

Func Set_Alarm()
    $Alarm_Hour = GUICtrlRead($hour)
    If $Alarm_Hour > 23 Or $Alarm_Hour = "" Then
        $Alarm_Hour = 0
        GUICtrlSetData($hour, "00")
    EndIf
    $Alarm_Min = GUICtrlRead($min)
    If $Alarm_Min > 59 Or $Alarm_Min = "" Then
        $Alarm_Min = 0
        GUICtrlSetData($min, "00")
    EndIf
    $Alarm_Sec = GUICtrlRead($sec)
    If $Alarm_Sec > 59 Or $Alarm_Sec = "" Then
        $Alarm_Sec = 0
        GUICtrlSetData($sec, "00")
    EndIf
    $EndTicks = _TimeToTicks($Alarm_Hour, $Alarm_Min, $Alarm_Sec)
EndFunc

Func On_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAnd($wParam, 0x0000FFFF)
    Switch $nNotifyCode
        Case 0x400;$EN_UPDATE
            If StringLen(GUICtrlRead($nID)) = 2 Then GUICtrlSetState($nID+1, $GUI_FOCUS)
    EndSwitch
EndFunc

M23

Thanks a lot! :P
Posted

Another thing:

I don't want to hide the clock when i click Stop. I want to set it to "00:00:00".

I tried with GuiCtrlSetData, but without results.

  • Moderators
Posted

FSoft,

It took me about 10 seconds to see how to do this. If you want to become a competent AutoIt coder, you have got to learn how to do simple things like this yourself. However......

Add a label which only reads "00:00:00" - then hide it with the timer when it is displayed. And because I am feeling really magnanimous, here is the new line to add:

$label1 = GUICtrlCreateLabel("00:00:00",20,20,100,20)

But you have to work out where it goes. ;-)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

FSoft,

It took me about 10 seconds to see how to do this. If you want to become a competent AutoIt coder, you have got to learn how to do simple things like this yourself. However......

Add a label which only reads "00:00:00" - then hide it with the timer when it is displayed. And because I am feeling really magnanimous, here is the new line to add:

$label1 = GUICtrlCreateLabel("00:00:00",20,20,100,20)

But you have to work out where it goes. ;-)

M23

Thank you very much :P

AutoIt is a simple scripting language and you can do many many things with a few strings; but, on the other hand, sometimes, it's difficult.

[This is only my opinion, I don't want to say that AutoIt sucks.. :P ]

Bye

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...