ashraful089 Posted January 31, 2023 Share Posted January 31, 2023 how to write this or declare, can anyone help please? Like, @hour=6 To @Hour=7 Then run a command thanks in advance If @HOUR = '6' And @MIN >= '5' Then Send("{[}") _Terminate() ElseIf (@HOUR >= '7' And @MIN >= '5') To (@HOUR >= '5' And @MIN >= '5') Then Send("{]}") _Terminate() EndIf Link to comment Share on other sites More sharing options...
ioa747 Posted January 31, 2023 Share Posted January 31, 2023 (edited) something like that Local $Time While 1 $Time = @HOUR & ":" & @MIN ConsoleWrite($Time & @CRLF) If $Time = "06:05" Then ;@HOUR = '6' And @MIN >= '5' Then Send("{[}") _Terminate() ElseIf $Time = "07:05" Then ;(@HOUR >= '7' And @MIN >= '5') To (@HOUR >= '5' And @MIN >= '5') Then Send("{]}") _Terminate() EndIf Sleep(1000 * 60) WEnd Edited January 31, 2023 by ioa747 ashraful089 1 I know that I know nothing Link to comment Share on other sites More sharing options...
ashraful089 Posted January 31, 2023 Author Share Posted January 31, 2023 Thanks @ioa747 this will be useful in next works but brother i asked about a declaration like " if hour = 6 to 8 then " Link to comment Share on other sites More sharing options...
ioa747 Posted January 31, 2023 Share Posted January 31, 2023 (edited) 18 minutes ago, ashraful089 said: if hour = 6 to 8 then this means 6 to 8 you send non-stop [ and _Terminate() ? Edited January 31, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
ashraful089 Posted January 31, 2023 Author Share Posted January 31, 2023 yes Link to comment Share on other sites More sharing options...
Nine Posted January 31, 2023 Share Posted January 31, 2023 if @hour >= 6 and @hour <= 8 then ... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
pixelsearch Posted January 31, 2023 Share Posted January 31, 2023 (edited) 21 minutes ago, Nine said: if @hour >= 6 and @hour <= 8 then ... In one of my scripts, I tested @hour and @min differently There was probably a reason for that, gonna think of it during lunch ; Réveil - TESTER AVANT, POUR ETRE SUR QUE WINDOWS A LES SONS SUR 'ON' ; Noter @HOUR = "hh" alors que @MIN >= "mm" While 1 If @HOUR = "14" And @MIN >= "00" Then ExitLoop Sleep(60 * 1000) ; 60 x 1s = 1min Wend While 1 Beep() Sleep(5000) ; 5s WEnd Edited January 31, 2023 by pixelsearch Link to comment Share on other sites More sharing options...
Nine Posted January 31, 2023 Share Posted January 31, 2023 (edited) It is because @hour returns a string ? as per help file : Quote mixed comparisons are usually made numerically Edited January 31, 2023 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
mistersquirrle Posted February 1, 2023 Share Posted February 1, 2023 (edited) @ashraful089 Yes, you can do a syntax like 6 to 8, using Switch. It would like something like this: While 1 Sleep(10) If __SwitchTime(6, 8) Then ConsoleWrite('Doing stuff' & @CRLF) __DoStuff() EndIf WEnd Func __SwitchTime($iStartHour, $iEndHour) Switch @HOUR Case $iStartHour To $iEndHour ConsoleWrite('Switch time true' & @CRLF) Return True Case Else ConsoleWrite('Not yet time' & @CRLF) EndSwitch EndFunc ;==>__SwitchTime Func __DoStuff() ;~ Send("{[}") ;~ _Terminate() EndFunc ;==>__DoStuff Or just more simply: Switch Number(@HOUR) Case 6 to 8 ConsoleWrite('True' & @CRLF) Case Else ConsoleWrite('False' & @CRLF) EndSwitch https://www.autoitscript.com/autoit3/docs/keywords/Switch.htm However I would take an approach like this if you're going to involve minutes as well: expandcollapse popup#include <StringConstants.au3> While 1 Sleep(1000) ; If you want to check for a time that spans across a day, such as starting at 22:05 until 02:05, do it like: ; If Not __CheckTime('02:05', '22:05') Then ;~ If __SwitchTime(6, 8) Then If __CheckTime('06:05', '07:05') Then __DoStuff() EndIf WEnd Func __CheckTime($sStart, $sEnd) ; Enums just for reference with names instead of numbers Local Enum $eTime_Hour, $eTime_Minute ; Split our starting time input, in the format HOUR:MINUTE Local $aStart = StringSplit($sStart, ':', $STR_ENTIRESPLIT + $STR_NOCOUNT) If @error Then ConsoleWrite('Invalid format of $sStart: ' & $sStart & ', error: ' & @error & @CRLF) Return SetError(1, 0, False) EndIf ; Split our ending time input, in the format HOUR:MINUTE Local $aEnd = StringSplit($sEnd, ':', $STR_ENTIRESPLIT + $STR_NOCOUNT) If @error Then ConsoleWrite('Invalid format of $sEnd: ' & $sEnd & ', error: ' & @error & @CRLF) Return SetError(2, 0, False) EndIf ; Convert the times into minutes Local $iStart = (Int($aStart[$eTime_Hour]) * 60) + $aStart[$eTime_Minute] Local $iEnd = (Int($aEnd[$eTime_Hour]) * 60) + $aEnd[$eTime_Minute] If $iEnd < $iStart Then ConsoleWrite('End time (' & $sEnd & ') is before start time (' & $sEnd & ')' & @CRLF) Return SetError(3, 0, False) EndIf ;~ ConsoleWrite('$iStart: ' & $iStart & ', $iEnd: ' & $iEnd & @CRLF) ; Get the current time as total minutes Local $iCurrentTime = (Int(@HOUR) * 60) + @MIN If $iCurrentTime >= $iStart And $iCurrentTime <= $iEnd Then ; We're in the time frame specified Return True EndIf ; We're not in the timeframe specified Return False EndFunc ;==>__CheckTime ; $iEndHour is optional, so as long as it's after the start hour in the same day, it'll return true Func __SwitchTime($iStartHour, $iEndHour = 24) Switch @HOUR Case $iStartHour To $iEndHour ConsoleWrite('Switch time true' & @CRLF) Return True Case Else ConsoleWrite('Not yet time' & @CRLF) EndSwitch EndFunc ;==>__SwitchTime Func __DoStuff() ConsoleWrite('Doing stuff' & @CRLF) ;~ Send("{[}") ;~ _Terminate() EndFunc ;==>__DoStuff Edited February 2, 2023 by mistersquirrle Updated code with some comments We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
ioa747 Posted February 1, 2023 Share Posted February 1, 2023 (edited) it can be expressed like this Local $Time While 1 $Time = Int(@HOUR) & "." & int(@MIN) ;ConsoleWrite($Time & @CRLF) Switch $Time Case 6.5 To 7.5 Send("{[}") _Terminate() Case 7.6 To 17.5 Send("{]}") _Terminate() EndSwitch Sleep(10) WEnd Edited February 1, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
jchd Posted February 1, 2023 Share Posted February 1, 2023 7 hours ago, ioa747 said: it can be expressed like this No, you're "expressing" something else! Hint: try running your program when @MIN is "05" and "50". Is there a difference? Why? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
ioa747 Posted February 1, 2023 Share Posted February 1, 2023 2 hours ago, jchd said: Hint: try running your program when @MIN is "05" and "50". Is there a difference? Why? sorry for the bad expressions but my English comes from Greek via google translate. I don't understand what exactly you mean by 'is there a difference?' what should i expect? that 05 and 50 would give me the same result? where is my mistake? Please explain me. Thank you ; https://www.autoitscript.com/forum/topic/209595-date-time-range/?do=findComment&comment=1512676 Local $Time While 1 $Time = Int(@HOUR) & "." & int(@MIN) ;ConsoleWrite($Time & @CRLF) Switch $Time Case 6.5 To 7.5 ;Send("{[}") _Terminate() Case 7.6 To 17.5 ;Send("{]}") _Terminate() EndSwitch Sleep(1000 * 60) WEnd Func _Terminate() ConsoleWrite($Time & @CRLF) EndFunc I am also attaching the results of the console Spoiler 15.48 15.49 15.50 15.51 15.52 15.53 15.54 15.55 15.56 15.57 15.58 15.59 16.0 16.1 16.2 16.3 16.4 16.5 16.6 16.7 16.8 16.9 16.10 16.11 16.12 I know that I know nothing Link to comment Share on other sites More sharing options...
Nine Posted February 1, 2023 Share Posted February 1, 2023 What @jchd means is : what's the difference between 16.5 (hr = 16 and mn = 05) and 16.50 (hr = 15 and mn = 50) from your example above ? None. In your script it is interpreted the same way. The issue is that you convert the string (@MIN) into an integer before you concatenate the whole thing into a string. Why? Since the end result is a string. But then your switch use a float (which means that your string is reconverted into a number), so both 16:05 and 16:50 are identical. Local $sTime = int("16") & "." & int("05") ; hr = 16 and mn = 05 Switch $sTime Case 15 to 16.5 ConsoleWrite("bw 15 - 16.5" & @CRLF) EndSwitch Local $sTime = int("16") & "." & int("50") ; hr = 16 and mn = 50 Switch $sTime Case 15 to 16.5 ConsoleWrite("bw 15 - 16.5" & @CRLF) EndSwitch To correctly use your approach, you should have done this : Local $nTime = Number(@HOUR & "." & @MIN) ; my current time is 10:20 ConsoleWrite($nTime & @CRLF) Switch $nTime Case 10 to 10.2 ConsoleWrite("bw 10 - 10.2" & @CRLF) EndSwitch ioa747 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
ioa747 Posted February 1, 2023 Share Posted February 1, 2023 @Nine Thank you very much for the detailed information. Now I understand where my mistake is @jchd Thank you for pointing it out I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted February 1, 2023 Share Posted February 1, 2023 (edited) After correction! Local $Time While 1 $Time = Number(@HOUR & "." & @MIN) ;ConsoleWrite($Time & @CRLF) Switch $Time Case 6.05 To 7.05 ;Send("{[}") _Terminate() Case 7.06 To 17.05 ;Send("{]}") _Terminate() EndSwitch Sleep(10) WEnd Edited February 1, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
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