IamKJ Posted April 17, 2017 Posted April 17, 2017 (edited) 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 April 17, 2017 by IamKJ
Subz Posted April 17, 2017 Posted April 17, 2017 Have you looked at TimerInit and TimerDiff functions?
IamKJ Posted April 17, 2017 Author Posted April 17, 2017 (edited) 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 April 17, 2017 by IamKJ
Subz Posted April 17, 2017 Posted April 17, 2017 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 IamKJ 1
IamKJ Posted April 17, 2017 Author Posted April 17, 2017 That worked perfectly. However, it won't allow me to use the _Msec function in _TimeToTicks, which returns milliseconds.
IamKJ Posted April 17, 2017 Author Posted April 17, 2017 It worked with the msgbox, but anything else I try to put after the Until statement just makes the original message box pop up.
Subz Posted April 17, 2017 Posted April 17, 2017 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 , IamKJ 1
IamKJ Posted April 19, 2017 Author Posted April 19, 2017 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!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now