Jump to content

Timed event?


Recommended Posts

  • Moderators

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:

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

 

Link to comment
Share on other sites

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

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 1 month later...

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
Link to comment
Share on other sites

  • Developers

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

Look at GuiCtrlRead()

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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:

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

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

  • Developers

Why do you assume that comparing numerically works with Time Strings?

You need to use _DateDiff() for that.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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:

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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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:

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

 

Link to comment
Share on other sites

  • Moderators

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:

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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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