Jump to content

Executing functions at specific times


 Share

Recommended Posts

I am trying to allow the GUI to gather info as to when to execute a function.  I am having trouble doing this.  So far this is what I have.

 

;Timer
Func timer ()
    If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(36,"Timer","Please format your answer in 00:00:00:000")
Select
    Case $iMsgBoxAnswer = 6 ;Yes
Global $infotime = InputBox ('Time', 'What time to execute?')

Do
$rawtimer = ToolTip(@Hour & ':' & @Min & ':' & @Sec & ':' & _MSec())
until $rawtimer = $infotime
if $rawtimer = $infotime Then
    msgbox (0,'Worked','Worked')
Else
    EndIf

    Case $iMsgBoxAnswer = 7 ;No
        Exit

EndSelect
EndFunc
Func _MSec()
    Local $stSystemTime = DllStructCreate('ushort;ushort;ushort;ushort;ushort;ushort;ushort;ushort')
    DllCall('kernel32.dll', 'none', 'GetSystemTime', 'ptr', DllStructGetPtr($stSystemTime))

    $sMilliSeconds = StringFormat('%03d', DllStructGetData($stSystemTime, 8))

    $stSystemTime = 0

    Return $sMilliSeconds
EndFunc

I have also tried _GUIToolTip_GetText in order to read the tooltip until the time specified, but it still doesn't work.  Any help would be great.

Edited by IamKJ
Link to comment
Share on other sites

Yes, but those only act from when it was called.  I want to go off of system time.  For example, this script would ask them to input time to execute, so I'd put "03:30:00:000", and I'd like for it to execute at 3:30 A.M.  

 

I can get the system time displayed fine and everything, but can't figure out how to get autoit to read the time as a string and execute when that system time string reaches to time specified.

 

It might be possible/easier for it to read the time as a whole number, maybe if you add all the times (hh + mm + ss + ms) and get a whole number, that might work, but not sure how to get autoit to read the system time as a string or integer.

Edited by IamKJ
Link to comment
Share on other sites

Sorry misread your post, what about:

#include <Date.au3>
Global $infotime
Global $iTicks
timer()
Func timer ()
    If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
    $iMsgBoxAnswer = MsgBox(36,"Timer","Please format your answer in 00:00:00")
    Select
        Case $iMsgBoxAnswer = 6 ;Yes
            $infotime = InputBox ('Time', 'What time to execute?')
            $iTicks = _TimeToTicks(StringLeft($infotime, 2), StringMid($infotime, 4, 2), StringRight($infotime, 2))
            Do
                ToolTip(@Hour & ':' & @Min & ':' & @Sec)
            Until _TimeToTicks(@HOUR, @MIN, @SEC) = $iTicks
            MsgBox(0,'Worked','Worked')
        Case $iMsgBoxAnswer = 7 ;No
            Exit
    EndSelect
EndFunc

 

Link to comment
Share on other sites

Can you give an example, I replaced the MsgBox with RunWait("Notepad.exe") and it worked fine.

Also regards your OP if you used the following it should also work, the issue previously is that you were reading ToolTip which just returned 0.

#include <Array.au3>
#include <Date.au3>
Global $infotime
timer()
Func timer ()
    $sTime = _DateAdd("s", 30, _NowCalc())
    $aTime = StringSplit($sTime, " ")
    $infotime = InputBox ('Time', 'What time to execute?', $aTime[2] & ":000")
    Do
        $sRawTimer = @Hour & ':' & @Min & ':' & @Sec & ':' & _MSec()
        ToolTip($sRawTimer)
    Until $sRawTimer = $infotime
    If $sRawTimer = $infotime Then MsgBox(0,'Worked','Worked')
EndFunc

Func _MSec()
    Local $stSystemTime = DllStructCreate('ushort;ushort;ushort;ushort;ushort;ushort;ushort;ushort')
    DllCall('kernel32.dll', 'none', 'GetSystemTime', 'ptr', DllStructGetPtr($stSystemTime))

    $sMilliSeconds = StringFormat('%03d', DllStructGetData($stSystemTime, 8))

    $stSystemTime = 0

    Return $sMilliSeconds
EndFunc

Link to comment
Share on other sites

The second code you posted worked beautifully every time.   It doesn't work all the time with the milliseconds, but that's fine, have found a way around that with using the sleep time and converting milliseconds into sleep time.  Thanks a lot!

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

×
×
  • Create New...