Jump to content

Recommended Posts

Posted

Hi there,

how would I go about making a timed event? 

Lets say I want notepad to open @ HH:MM:SS

What command should I look at, preferably with some example code!

Thanks guys!

  • Moderators
Posted

Scinner,

I would suggest something with the @HOUR, @MIN & @SEC macros in an If structure. :)

Or _NowCalc with a bit of string manipulation. ;)

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:

  Reveal hidden contents

 

Posted

...and using the Date UDF with AdlibRegister.

#include <Constants.au3>
#include <Date.au3>

Example()

Func Example()
    ; Add 1 minute to the current date and time, then find the difference.
    Local $iMilliSeconds_Wait = _DateDiff('s', _NowCalc(), _DateAdd('n', 1, _NowCalc())) * 1000
    AdlibRegister('OpenNotepad', $iMilliSeconds_Wait)

    MsgBox($MB_SYSTEMMODAL, '', 'Notepad will open in ' & $iMilliSeconds_Wait & 'ms')

    While 1
        Sleep(250)
    WEnd
EndFunc   ;==>Example

Func OpenNotepad()
    AdlibUnRegister('OpenNotepad')
    Local $iPID = Run('notepad')
    MsgBox($MB_SYSTEMMODAL, '', 'Notepad is running using the PID: ' & $iPID & @CRLF & @CRLF & _
            'The example will now close.')
    Exit
EndFunc   ;==>OpenNotepad

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 1 month later...
Posted

Im trying this code but it won't work. Can you please help me?

#include <GUIConstantsEx.au3>
#include <Date.au3>

Example()

Func Example()
    Local $Button_1, $msg
    GUICreate("Timed Notepad Launcher", 300, 40)
    Opt("GUICoordMode", 1)
    GuiCtrlCreateLabel("Time:", 10, 10)
    $tid = GuiCtrlCreateInput("00:00:00", 40, 7, 50, 20)
    $Button_1 = GUICtrlCreateButton("Launch Notepad @ Set Time", 100, 5, 150)
    GUISetState(@SW_SHOW)
While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                If $tid = _NowTime(5) Then
                Run ("Notepad")
                EndIf
            EndSelect

    WEnd
EndFunc   ;==>Example
Posted
  On 7/27/2013 at 3:19 PM, Jos said:

You are not getting the value from the Control but are comparing to it's Handle.

Look at GuiCtrlRead()

Jos

This wont work either?

#include <GUIConstantsEx.au3>
#include <Date.au3>
Example()

Func Example()
    Local $Button_1, $msg, $tid, $menutext, $GUI_EVENT_CLOSE
    GUICreate("Timed Notepad Launcher", 300, 40)
    Opt("GUICoordMode", 1)
    GuiCtrlCreateLabel("Time:", 10, 10)
    $tid = GuiCtrlCreateInput("00:00:00", 40, 7, 50, 20)
    $Button_1 = GUICtrlCreateButton("Launch Notepad @ Set Time", 100, 5, 150)
    GUISetState(@SW_SHOW)
While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                If GUICtrlRead($tid, 0) = _NowTime(5) Then
                ;If $tid <= _NowTime(5) Then
                Run ("Notepad")
                EndIf
            EndSelect

    WEnd
EndFunc   ;==>Example
  • Moderators
Posted

Scinner,

You are only checking the time when you press the button - so unless you press it at exactly the time specified, the condition is not met and you will not start Notepad.  And you are not actually checking the time - only the ControlID of the input. :(

I suggest that you do something like this:

#include <GUIConstantsEx.au3>
#include <Date.au3>

Example()

Func Example()
    Local $Button_1, $msg, $fWaiting = False, $sTime
    GUICreate("Timed Notepad Launcher", 300, 40)
    GUICtrlCreateLabel("Time:", 10, 10)
    $tid = GUICtrlCreateInput("00:00:00", 40, 7, 50, 20)
    $Button_1 = GUICtrlCreateButton("Launch Notepad @ Set Time", 100, 5, 150)
    GUISetState(@SW_SHOW)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Button_1
                $sTime = GUICtrlRead($tid)
                $fWaiting = True
                GUICtrlSetData($Button_1, "Launch Notepad @" & $sTime)
        EndSwitch

        If $fWaiting Then
            If $sTime = _NowTime(5) Then
                Run ("Notepad")
                $fWaiting = False
            EndIf
        EndIf

    WEnd
EndFunc   ;==>Example

That is actually checkiing every few miiliseconds, which is a bit OTT.  You could refine it to look at different intervals depending on how close to the required time you get - but you can work on that. ;)

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:

  Reveal hidden contents

 

Posted
  On 7/27/2013 at 3:31 PM, Jos said:

You do realize this only works when you click exactly at the correct time ...right?

If I try with more than/less than it still doesen't work.

#include <GUIConstantsEx.au3>
#include <Date.au3>
Example()

Func Example()
    Local $Button_1, $msg, $tid, $menutext, $GUI_EVENT_CLOSE
    GUICreate("Timed Notepad Launcher", 300, 40)
    Opt("GUICoordMode", 1)
    GuiCtrlCreateLabel("Time:", 10, 10)
    $tid = GuiCtrlCreateInput("00:00:00", 40, 7, 50, 20)
    $Button_1 = GUICtrlCreateButton("Launch Notepad @ Set Time", 100, 5, 150)
    GUISetState(@SW_SHOW)
While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                If GUICtrlRead($tid, 0) <= _NowTime(5) Then
                Run ("Notepad")
                EndIf
            EndSelect

    WEnd
EndFunc   ;==>Example

Please help me!

Posted

  On 7/27/2013 at 3:32 PM, Melba23 said:

Scinner,

You are only checking the time when you press the button - so unless you press it at exactly the time specified, the condition is not met and you will not start Notepad.  And you are not actually checking the time - only the ControlID of the input. :(

I suggest that you do something like this:

#include <GUIConstantsEx.au3>
#include <Date.au3>

Example()

Func Example()
    Local $Button_1, $msg, $fWaiting = False, $sTime
    GUICreate("Timed Notepad Launcher", 300, 40)
    GUICtrlCreateLabel("Time:", 10, 10)
    $tid = GUICtrlCreateInput("00:00:00", 40, 7, 50, 20)
    $Button_1 = GUICtrlCreateButton("Launch Notepad @ Set Time", 100, 5, 150)
    GUISetState(@SW_SHOW)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Button_1
                $sTime = GUICtrlRead($tid)
                $fWaiting = True
                GUICtrlSetData($Button_1, "Launch Notepad @" & $sTime)
        EndSwitch

        If $fWaiting Then
            If $sTime = _NowTime(5) Then
                Run ("Notepad")
                $fWaiting = False
            EndIf
        EndIf

    WEnd
EndFunc   ;==>Example

That is actually checkiing every few miiliseconds, which is a bit OTT.  You could refine it to look at different intervals depending on how close to the required time you get - but you can work on that. ;)

M23

Thx mate! That was what I was looking for!!

Posted

I have one more question.

I got the Current system time to show in my gui. How can I make this update every 1000ms?

#include <GUIConstantsEx.au3>
#include <Date.au3>



 Example()

Func Example()
    Local $Button_1, $current, $fWaiting = False, $sTime
    GUICreate("Timed Notepad", 450, 90)
    GUICtrlCreateLabel("Time:", 10, 40)
    $current = GuiCtrlCreatelabel("Current Time : " & _NowTime(), 10, 10, 200, 20) ; <----- I want this to update every 1000ms as a regular clock
    $tid = GUICtrlCreateInput("00:00:00", 50, 37, 50, 20)
    $Button_1 = GUICtrlCreateButton("Open Notepad @ Time", 120, 34, 150)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Button_1
                $sTime = GUICtrlRead($tid)
                $fWaiting = True
                GUICtrlSetData($Button_1, "Open Notepad @" & $sTime)
        EndSwitch

        If $fWaiting Then
            If $sTime = _NowTime(5) Then
                Run ("Notepad.exe")
                $fWaiting = False
            EndIf
        EndIf

    WEnd
EndFunc   ;==>Example
  • Moderators
Posted (edited)

Scinner,

Either use an Adlib function with a 1000ms interval or use TimerInit/TimerDiff in the loop to check for the 1000ms delay since the last update. :)

Give it a go yourself and come back if you run into problems. ;)

M23

Edited by Melba23
Typo

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:

  Reveal hidden contents

 

Posted

  On 8/1/2013 at 12:24 PM, Melba23 said:

Scinner,

Either use an Adlib function with a 1000ms interval or use TimerInit/TimerDiff in the loop to check for the 1000ms delay since the last update. :)

Give it a go yourself and come back if you run into problems. ;)

M23

I think I got it!

Only thing is the "Current Time" shows up 2 seconds after gui launch. Its really not a problem but can you tell me why it takes 2 seconds for the Curr Time to show up?

#include <GUIConstantsEx.au3>
#include <Date.au3>

AdlibRegister("MyAdlib",1000)
Func MyAdlib()
    $current = GuiCtrlCreatelabel("Current Time : " & _NowTime(), 10, 10, 200, 20)
EndFunc   ;==>MyAdlib

 Example()

Func Example()
    Local $Button_1, $current, $fWaiting = False, $sTime
    GUICreate("Timed Notepad", 450, 90)
    GUICtrlCreateLabel("Time:", 10, 40)
    $tid = GUICtrlCreateInput("00:00:00", 50, 37, 50, 20)
    $Button_1 = GUICtrlCreateButton("Open Notepad @ Time", 120, 34, 150)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Button_1
                $sTime = GUICtrlRead($tid)
                $fWaiting = True
                GUICtrlSetData($Button_1, "Open Notepad @" & $sTime)
        EndSwitch

        If $fWaiting Then
            If $sTime = _NowTime(5) Then
                Run ("Notepad.exe")
                $fWaiting = False
                EndIf
            EndIf
    WEnd
EndFunc   ;==>Example
  • Moderators
Posted

Scinner,

There is a pause because the first Adlib call is only made after the set interval - just call the function yourself the first time. ;)

And if you create the label just the once you can update it in the Adlib like this:

#include <GUIConstantsEx.au3>
#include <Date.au3>

Global $cLabel ; The label ControlID needs to be Global <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

AdlibRegister("MyAdlib", 1000)

Example()

Func Example()
    Local $Button_1, $current, $fWaiting = False, $sTime
    GUICreate("Timed Notepad", 450, 90)
    $cLabel = GUICtrlCreateLabel("", 10, 10, 200, 20) ; Create the label here <<<<<<<<<<<<<
    MyAdlib() ; Call the function here to set the initial time <<<<<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlCreateLabel("Time:", 10, 40)
    $tid = GUICtrlCreateInput("00:00:00", 50, 37, 50, 20)
    $Button_1 = GUICtrlCreateButton("Open Notepad @ Time", 120, 34, 150)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Button_1
                $sTime = GUICtrlRead($tid)
                $fWaiting = True
                GUICtrlSetData($Button_1, "Open Notepad @" & $sTime)
        EndSwitch

        If $fWaiting Then
            If $sTime = _NowTime(5) Then
                Run("Notepad.exe")
                $fWaiting = False
            EndIf
        EndIf
    WEnd
EndFunc   ;==>Example

Func MyAdlib()
    GUICtrlSetData($cLabel, "Current Time : " & _NowTime()) ; And update it here <<<<<<<<<<<
EndFunc   ;==>MyAdlib
All clear? :)

 

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:

  Reveal hidden contents

 

  • Moderators
Posted

Scinner,

Glad I could help - again! :D

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:

  Reveal hidden contents

 

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...