Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/19/2021 in all areas

  1. Gianni

    Aquarium

    This script is an alternative (improvement) to the script published at this link (www.autoitscript.com/forum/topic/186225-interesting-effect-with-transparency). In that post a flash animation was used and therefore you need the flash player to work, while here only javascript is used. Here, too, the aim is to show an interesting effect that can be obtained by exploiting transparency, but can also be used as it is just for fun. The animation consists of some fish wandering around the screen. You can continue working on the computer by letting them swim. The javascript source was not written by me, but I got it from this link: https://github.com/lrusso/Aquarium. I shrunk it down a bit and tweaked it so that fish can swim across the entire screen even with different sized monitors. The fish images and html and javascript sources have been bundled into a single "monolithic" AutoIt script, so it's easier to run. I hope you find it relaxing. Have fun fishMonolitic.zip
    4 points
  2. PDH Performance Counters Measure Process, CPU, Network, Process, Disk (etc) Usage (note that the above dialog appears differently on Vista+) New ObjectBase interface!! *x64 and Localization Issues have been resolved!* *Download and License agreement are at the bottom of this post! About The Project: Performance Counters gather all kind of performance data about the PC and the Network using the standard PDH.DLL module (standard since Windows 2000). Among the performance data you can collect and monitor are: Processor Stats (including total usage)Process (programs) Stats (including CPU usage)Disk Stats (speed/access)TCP, UDP, IP Connection Counts, Speed/Error StatsNetwork Stats..and so onNote that one example is a WIP. 'TaskManager' mockup UDF, I'm looking at you. You can jump right in, download the two AutoIT files (below) and run one of the following to see what the PDH Performance Counters project can get you: TestPDH_PerformanceCounters - this is where you should start! It allows you to visually experiment with most all of the Counters available on your PC and Network. NOTES: - Currently the 'Refresh' rate is set to 1/2 second - this can be changed by altering the Adlib() function frequency - New Counters that come into existence during monitoring will *not* be added to the list (this would be a function I've yet to add) - Counters that become invalid are simply given a prefix of '[Dead Counter Handle]:' TestPDH_ProcessLoop - this basically repeatedly shows an extended Process-information list for all processes. NOTE: You must hit 'ESC' to exit the loop TestPDH_TaskManager - this gathers and displays most everything you'd see in the Process and Performance sections of Task Manager. NOTES: - The screen does NOT update, and the UDF is a MESS. This is due to a number of reasons - the biggest one being laziness on my behalf. Plus I need to figure out how best to manage ListView changes. - TWO fields need Windows XP+ to display correctly (or a version of psapi.dll that supports 'GetPerformanceInfo'): Commit Charge (Peak) and System Cache TestPDH_ProcessGetRelatives - this shows how the PDH Performance Counters can be used to get 'parent' and 'children' process information. There are more practical means of getting this info of course (a few you'll see in my 'Process Functions' module, but hey - its just yet another example of what can be done.TestPDH_ObjectTests - this is more for reading/understanding the code than anything. It is there to show how the new 'ObjectBase' Interface works to make coding Performance Counters *much* easier.Multipile extra 'TestPDH*' examplesAt its most basic, interacting with Performance Counters is as such: The brand new ObjectBase Interface removes some of the difficulty in interacting with Performance Counters, and works like this: Examples of the new ObjectBase interface: % CPU Usage of a Process % CPU Usage of Multiple Instances of a Process (+monitoring and adjustment based on new/dead Instances) Other Examples: Waiting for Hard Disk activity to Idle for 'x' ms % System CPU Usage (by Processor) Network Usage (bytes sent/received) I've put a LOT of work into this project, and all I ask is that you follow my License Agreement when using the code (very easy, see below). Any feedback is welcome. I apologize for the unpolished GUI interfaces (especially the unfinished one), but I will get to that TaskManager GUI one day, hah. Enough chatter -now go on and experience the awesome power of Performance Counters Download the ZIP Here NOTE: Bundled in the ZIP (and included in the License agreement) are other UDF's I wrote that are necessary to run some of the 'Test' programs:_WinAPI_GetSystemInfo.au3, _WinAPI_GetPerformanceInfo.au3, _WinTimeFunctions.au3, and the unnecessary, but provided for those who are interested in the _WinTimeFunctions 'filetime' usage, program: TestWinTimeFunctions.au3. Ascend4nt's AutoIT Code License agreement: While I provide this source code freely, if you do use the code in your projects, all I ask is that: If you provide source, keep the header as I have put it, OR, if you expand it, then at least acknowledge me as the original author, and any other authors I creditIf the program is released, acknowledge me in your credits (it doesn't have to state which functions came from me, though again if the source is provided - see #1)The source on it's own (as opposed to part of a project) can not be posted unless a link to the page(s) where the code were retrieved from is provided and a message stating that the latest updates will be available on the page(s) linked to.Pieces of the code can however be discussed on the threads where Ascend4nt has posted the code without worrying about further linking.Enjoy!Ascend4nt UPDATES:
    1 point
  3. Look at _ArrayMin() EDIT: Sorry I overlooked needed condition for zero/negative numbers, so as TheDCoder said ... here example from helpfile: #include <Array.au3> Local $avArray = StringSplit("4,2,06,8,12,5", ",") MsgBox(0,'Min String value', _ArrayMin($avArray, 0, 1)) MsgBox(0,'Min Numeric value', _ArrayMin($avArray, 1, 0))
    1 point
  4. Don’t take @Musashi’s reticence to indicate anything besides his limitless tolerance for overtly fatuous responses.
    1 point
  5. TheDcoder

    Aquarium

    Sorry for the off-topic subject, but I recall a very similar desktop "game" which looks nearly identical to the JS game, infact both of them aren't really games, it's just a bunch of fish moving It was many many years ago and I felt nostalgic, so thought I'd share. If anyone knows what it's called then they can share it with me.
    1 point
  6. Hello. Maybe adapting this you could get some similar result. Local $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2") Local $ocolProcesses = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfRawData_PerfProc_Process WHERE NAME <> '_Total'", Default, 0x30) For $oProcess In $ocolProcesses ConsoleWrite(">" & $oProcess.Name & @CRLF) ConsoleWrite($oProcess.IOReadBytesPerSec & @CRLF) ConsoleWrite($oProcess.IOReadOperationsPerSec & @CRLF) ConsoleWrite($oProcess.IOWriteBytesPerSec & @CRLF) ConsoleWrite($oProcess.IOWriteOperationsPerSec & @CRLF) ConsoleWrite($oProcess.IOOtherBytesPerSec & @CRLF) ConsoleWrite($oProcess.IOOtherOperationsPerSec & @CRLF) ConsoleWrite($oProcess.PageFaultsPersec & @CRLF) ConsoleWrite(@CRLF) Next Saludos
    1 point
  7. Sounds like a "driver issue".
    1 point
  8. Here is a UDF that I created when I had to do a large project working with dates and times, and calculations with them. I need to convert the time from 12 hr time with "AM" and "PM", and sometimes with "a" and "p", to 24 hr time for calculations, and convert the time back to 12 hr when needed. I also needed to convert "MM/DD/YYYY" to "YYYY/MM/DD" for use in calculations as well, and convert back as well. For details on each function, please look at the function headers. Look at Melba23's more flexible Date_Time_Convert UDF. I use that UDF more now than this one, but I still use "IsBetween" functions in this UDF. DateTimeConvert.au3 #include-once #include <Date.au3> #AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y ; #INDEX# ======================================================================================================================= ; Title .........: Time and Date Conversion Library ; AutoIt Version : 3.3.6++ ; UDF Version ...: 1.1 ; Language ......: English ; Description ...: Converts time between 12 hr and 24 hr with other time and date related functions. ; Dll ...........: ; Author(s) .....: Adam Lawrence (AdamUL) ; Email .........: ; Modified.......: ; Contributors ..: ; Resources .....: ; Remarks .......: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_IsTime12Hr ;_IsTime24Hr ;_Time12HrTo24Hr ;_Time24HrTo12Hr ;_IsCalcDate ;_IsStandardDate ;_IsDateAndTime ;_DateStandardToCalcDate ;_DateCalcToStandardDate ;_IsBetweenTimes ;_IsBetweenDatesTimes ;_IsBetweenDatesTimesLite ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IsTime12Hr ; Description ...: Checks to see if a time string is in the 12 hr (AM/PM) format. ; Syntax ........: _IsTime12Hr($sTime) ; Parameters ....: $sTime - A string value in time format. ; Return values .: Success - True ; Failure - False, sets @error to: ; |0 - String is not in 12 hr time format. ; |1 - Invalid time format string. ; Author ........: Adam Lawrence (AdamUL) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _IsTime12Hr($sTime) If StringRegExp($sTime, "^(1[0-2]|[1-9]):([0-5]\d):?([0-5]\d)?(?-i:\h*)(?i)([ap]m?)$") Then Return True If @error Then Return SetError(1, 0, False) Return False EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IsTime24Hr ; Description ...: Checks to see if a time string is in the 24 hr format. ; Syntax ........: _IsTime24Hr($sTime) ; Parameters ....: $sTime - A string value in time format. ; Return values .: Success - True ; Failure - False, sets @error to: ; |0 - String is not in 24 hr time format. ; |1 - Invalid time format string. ; Author ........: Adam Lawrence (AdamUL) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _IsTime24Hr($sTime) If StringRegExp($sTime, "^([01]?\d|2[0-3]):([0-5]\d):?([0-5]\d)?$") Then Return True If @error Then Return SetError(1, 0, False) Return False EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Time12HrTo24Hr ; Description ...: Convert 12 hr (AM/PM) time string to a 24 hr time string. ; Syntax ........: _Time12HrTo24Hr($sTime[, $fDisplaySecs = True[, $fHourLeadingZero = False]]) ; Parameters ....: $sTime - "hh:mm:ss AM/PM" time format. ; $fDisplaySecs - [optional] A boolean value to display seconds values. Default is True. ; $fHourLeadingZero - [optional] A boolean value to pad leading zero to single digit hours. Default is False. ; Return values .: Success - A string value in "hh:mm:ss" 24 hr time string. ; Failure - "", sets @error to: ; |1 - Invalid time format string ; Author ........: Adam Lawrence (AdamUL) ; Modified ......: ; Remarks .......: ; Related .......: _Time24HrTo12Hr ; Link ..........: ; Example .......: _Time12HrTo24Hr("12:30AM"), _Time12HrTo24Hr("1:30:45 PM"), _Time12HrTo24Hr("12:30 pm") ; =============================================================================================================================== Func _Time12HrTo24Hr($sTime, $fDisplaySecs = True, $fHourLeadingZero = False) Local $aTime = StringRegExp($sTime, "^(1[0-2]|[1-9]):([0-5]\d):?([0-5]\d)?(?-i:\h*)(?i)([ap]m?)$", 1) If @error Then Return SetError(1, 0, "") Local $sHour = $aTime[0] Local $sMins = $aTime[1] Local $sSecs = $aTime[2] Local $sAMPM = $aTime[3] $sHour = Mod($sHour, 12) If StringInStr($sAMPM, "p") Then $sHour += 12 If $fHourLeadingZero And Number($sHour) < 10 And StringLen($sHour) = 1 Then $sHour = "0" & $sHour If $fDisplaySecs And $sSecs = "" Then $sSecs = "00" If $fDisplaySecs Then Return $sHour & ":" & $sMins & ":" & $sSecs Return $sHour & ":" & $sMins EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Time24HrTo12Hr ; Description ...: Convert 24 hr time string to a 12 hr (AM/PM) time string. ; Syntax ........: _Time24HrTo12Hr($sTime[, $fDisplaySecs = True[, $fHourLeadingZero = False[, $sAMPMDelim = " "]]]) ; Parameters ....: $sTime - A string value in "hh:mm:ss" time format. ; $fDisplaySecs - [optional] A boolean value to display seconds values. Default is True. ; $fHourLeadingZero - [optional] A boolean value to pad leading zero to single digit hours. Default is False. ; $sAMPMDelim - [optional] A string value delimiter to seperate AM/PM from the numeric time. Default is " ". ; Return values .: Success - "hh:mm:ss AM/PM" time format. ; Failure - "", sets @error to: ; |1 - Invalid time format string. ; Author ........: Adam Lawrence (AdamUL) ; Modified ......: ; Remarks .......: ; Related .......: _Time12HrTo24Hr ; Link ..........: ; Example .......: _Time24HrTo12Hr("0:30"), _Time24HrTo12Hr("15:45:36"), _Time24HrTo12Hr("5:36") ; =============================================================================================================================== Func _Time24HrTo12Hr($sTime, $fDisplaySecs = True, $fHourLeadingZero = False, $sAMPMDelim = " ") Local $aTime = StringRegExp($sTime, "^([01]?\d|2[0-3]):([0-5]\d):?([0-5]\d)?$", 1) If @error Then Return SetError(1, 0, "") If UBound($aTime) = 2 Then ReDim $aTime[3] Local $sHour = $aTime[0] Local $sMins = $aTime[1] Local $sSecs = $aTime[2] Local $sAMPM = "" Switch $sHour Case 0 $sHour = 12 $sAMPM = "AM" Case 1 To 11 $sAMPM = "AM" Case 12 $sAMPM = "PM" Case 13 To 23 $sHour = $sHour - 12 $sAMPM = "PM" Case Else EndSwitch If $fHourLeadingZero And Number($sHour) < 10 And StringLen($sHour) = 1 Then $sHour = "0" & $sHour If Not $fHourLeadingZero And Number($sHour) < 10 And StringLen($sHour) = 2 Then $sHour = Number($sHour) If $fDisplaySecs And $sSecs = "" Then $sSecs = "00" If $fDisplaySecs Then Return $sHour & ":" & $sMins & ":" & $sSecs & $sAMPMDelim & $sAMPM Return $sHour & ":" & $sMins & $sAMPMDelim & $sAMPM EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IsCalcDate ; Description ...: Checks to see if a date is in a format for calculations. ; Syntax ........: _IsCalcDate($sDate) ; Parameters ....: $sDate - A string value date format. ; Return values .: Success - True ; Failure - False, sets @error to 1. ; Author ........: Adam Lawrence (AdamUL) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _IsCalcDate($sDate) If StringRegExp($sDate, "^(\d{4})/(\d{1,2})/(\d{1,2})$") Then Return True If @error Then Return SetError(1, 0, False) Return False EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IsStandardDate ; Description ...: Checks to see if a date is in a standard date format, "MM/DD/YYYY". ; Syntax ........: _IsStandardDate($sDate) ; Parameters ....: $sDate - A string value in date format. ; Return values .: Success - True ; Failure - False, sets @error to 1. ; Author ........: Adam Lawrence (AdamUL) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _IsStandardDate($sDate) If StringRegExp($sDate, "^(\d{1,2})/(\d{1,2})/(\d{4})$") Then Return True If @error Then Return SetError(1, 0, False) Return False EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IsDateAndTime ; Description ...: Checks to see if a string is in a date and time format. ; Syntax ........: _IsDateAndTime($sDateTime) ; Parameters ....: $sDateTime - A string value in date and time format. ; Return values .: Success - True ; Failure - False, sets @error to 1. ; Author ........: Adam Lawrence (AdamUL) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _IsDateAndTime($sDateTime) Local $sRegEx = "^((?:\d{1,2}/\d{1,2}/\d{4})|(?:\d{4}/\d{1,2}/\d{1,2}))?(?-i:\h*)?((?:1[0-2]|[1-9]):(?:[0-5]\d):?(?:[0-5]\d)?(?-i:\h*)(?i:[ap]m?)|(?:[01]?\d|2[0-3]):(?:[0-5]\d):?(?:[0-5]\d)?)$" If StringRegExp($sDateTime, $sRegEx) Then Return True If @error Then Return SetError(1, 0, False) Return False EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DateStandardToCalcDate ; Description ...: Convert a date from "MM/DD/YYYY" to "YYYY/MM/DD" format to use in date calculations. ; Syntax ........: _DateStandardToCalcDate($sDate) ; Parameters ....: $sDate - A string value in "MM/DD/YYYY" format. ; Return values .: Success - Calc date string. ; Failure - "", sets @error to: ; |1 - Invalid date format. ; Author ........: Adam Lawrence (AdamUL) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _DateStandardToCalcDate($sDate) If Not StringRegExp($sDate, "^(\d{1,2})/(\d{1,2})/(\d{4})$") Then Return SetError(1, 0, "") If @error Then Return SetError(1, 0, "") Local $sDateNew = StringRegExpReplace($sDate, "(\d{2})/(\d{2})/(\d{4})", "$3/$1/$2") $sDateNew = StringRegExpReplace($sDateNew, "(\d{2})/(\d)/(\d{4})", "$3/$1/0$2") $sDateNew = StringRegExpReplace($sDateNew, "(\d)/(\d{2})/(\d{4})", "$3/0$1/$2") $sDateNew = StringRegExpReplace($sDateNew, "(\d)/(\d)/(\d{4})", "$3/0$1/0$2") Return $sDateNew EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DateCalcToStandardDate ; Description ...: Convert a date from "YYYY/MM/DD" to "MM/DD/YYYY" format. ; Syntax ........: _DateCalcToStandardDate($sDate) ; Parameters ....: $sDate - A string value in "YYYY/MM/DD" format. ; Return values .: Success - Standard date string ; Failure - "", sets @error to: ; |1 - Invalid date format. ; Author ........: Adam Lawrence (AdamUL) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _DateCalcToStandardDate($sDate) Local $aDate = StringRegExp($sDate, "^(\d{4})/(\d{1,2})/(\d{1,2})$", 1) If @error Then Return SetError(1, 0, "") Local $sYear = $aDate[0] Local $sMonth = $aDate[1] Local $sDay = $aDate[2] Return Number($sMonth) & "/" & Number($sDay) & "/" & $sYear EndFunc Func _DateTimeStandardToCalcDateTime($sDateTime) Local $sRegEx = "^((?:\d{1,2}/\d{1,2}/\d{4})|(?:\d{4}/\d{1,2}/\d{1,2}))?(?-i:\h*)?((?:1[0-2]|[1-9]):(?:[0-5]\d):?(?:[0-5]\d)?(?-i:\h*)(?i:[ap]m?)|(?:[01]?\d|2[0-3]):(?:[0-5]\d):?(?:[0-5]\d)?)$" Local $aDateTime = StringRegExp($sDateTime, $sRegEx, 1) If @error Then Return SetError(1, 1, "") Local $sDate = $aDateTime[0] Local $sTime = $aDateTime[1] If _IsStandardDate($sDate) Then $sDate = _DateStandardToCalcDate($sDate) If @error Then Return SetError(2, 1, "") EndIf If Not _IsCalcDate($sDate) Then Return SetError(2, 2, "") If _IsTime12Hr($sTime) Then $sTime = _Time12HrTo24Hr($sTime) If @error Then Return SetError(3, 1, "") EndIf If Not _IsTime24Hr($sTime) Then Return SetError(3, 2, "") Return $sDate & " " & $sTime EndFunc Func _DateTimeCalcToStandardDateTime($sDateTime) Local $sRegEx = "^((?:\d{1,2}/\d{1,2}/\d{4})|(?:\d{4}/\d{1,2}/\d{1,2}))?(?-i:\h*)?((?:1[0-2]|[1-9]):(?:[0-5]\d):?(?:[0-5]\d)?(?-i:\h*)(?i:[ap]m?)|(?:[01]?\d|2[0-3]):(?:[0-5]\d):?(?:[0-5]\d)?)$" Local $aDateTime = StringRegExp($sDateTime, $sRegEx, 1) If @error Then Return SetError(1, 1, "") Local $sDate = $aDateTime[0] Local $sTime = $aDateTime[1] If _IsCalcDate($sDate) Then $sDate = _DateCalcToStandardDate($sDate) If @error Then Return SetError(2, 1, "") EndIf If Not _IsStandardDate($sDate) Then Return SetError(2, 2, "") If _IsTime24Hr($sTime) Then $sTime = _Time24HrTo12Hr($sTime) If @error Then Return SetError(3, 1, "") EndIf If Not _IsTime12Hr($sTime) Then Return SetError(3, 2, "") Return $sDate & " " & $sTime EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IsBetweenTimes ; Description ...: Test a time to see if it is between the Start Time and the End Time in a 24 hour day. ; Syntax ........: _IsBetweenTimes($sTestTime, $sStartTime, $sEndTime) ; Parameters ....: $sTestTime - A string value time to test, in 12 hr or 24 hr format. ; $sStartTime - A string value start Time, must be before End Time in 12 hr or 24 hr format. ; $sEndTime - A string value end Time, must be after Start Time in 12 hr or 24 hr format. ; Return values .: Success - True ; Failure - False, sets @error to: ; |0 - Not between times. ; |1 - Invalid 12 Hr format. ; |2 - Invalid 24 Hr format. ; |3 - Invalid time string. ; |4 - End Time before Start Time. ; Author ........: Adam Lawrence (AdamUL) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _IsBetweenTimes($sTestTime, $sStartTime, $sEndTime) If _IsTime12Hr($sTestTime) Then $sTestTime = _Time12HrTo24Hr($sTestTime) If @error Then Return SetError(1, 1, False) EndIf If _IsTime12Hr($sStartTime) Then $sStartTime = _Time12HrTo24Hr($sStartTime) If @error Then Return SetError(1, 2, False) EndIf If _IsTime12Hr($sEndTime) Then $sEndTime = _Time12HrTo24Hr($sEndTime) If @error Then Return SetError(1, 3, False) EndIf If Not _IsTime24Hr($sTestTime) Then Return SetError(2, 1, False) If Not _IsTime24Hr($sStartTime) Then Return SetError(2, 2, False) If Not _IsTime24Hr($sEndTime) Then Return SetError(2, 3, False) $sTestTime = StringReplace(StringStripWS($sTestTime, 8), ":", "") If @error Or @extended > 2 Then Return SetError(3, 1, False) If @extended = 1 Then $sTestTime &= "00" Local $iTestTime = Number($sTestTime) $sStartTime = StringReplace(StringStripWS($sStartTime, 8), ":", "") If @error Or @extended > 2 Then Return SetError(3, 2, False) If @extended = 1 Then $sStartTime &= "00" Local $iStartTime = Number($sStartTime) $sEndTime = StringReplace(StringStripWS($sEndTime, 8), ":", "") If @error Or @extended > 2 Then Return SetError(3, 3, False) If @extended = 1 Then $sEndTime &= "00" Local $iEndTime = Number($sEndTime) If $iEndTime < $iStartTime Then Return SetError(4, 0, False) If $iTestTime >= $iStartTime And $iTestTime <= $iEndTime Then Return True Return False EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IsBetweenDatesTimes ; Description ...: Test a time to see if it is between the Start Date and Time and the End Date and Time. ; Syntax ........: _IsBetweenDatesTimes($sTestDateTime, $sStartDateTime, $sEndDateTime) ; Parameters ....: $sTestDateTime - A string value, Date and Time to test, in 12 hr or 24 hr format "YYYY/MM/DD[ HH:MM:SS]". ; $sStartDateTime - A string value, Start Date and Time, must be before End Date and Time in 12 hr or 24 hr format "YYYY/MM/DD[ HH:MM:SS]". ; $sEndDateTime - A string value, End Date and Time, must be after Start Date and Time in 12 hr or 24 hr format "YYYY/MM/DD[ HH:MM:SS]". ; Return values .: Success - True ; Failure - False, sets @error to: ; |1 - Invalid date format. ; |2 - Error Converting to Calc date. ; |3 - Invalid time format. ; |4 - Invalid $sTestDateTime ; |5 - Invalid $sStartDateTime ; |6 - Invalid $sEndDateTime ; Author ........: Adam Lawrence (AdamUL) ; Modified ......: ; Remarks .......: ; Related .......: _IsBetweenDatesTimesLite, _IsBetweenTimes ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _IsBetweenDatesTimes($sTestDateTime, $sStartDateTime, $sEndDateTime) Local $sRegEx = "^((?:\d{1,2}/\d{1,2}/\d{4})|(?:\d{4}/\d{1,2}/\d{1,2}))?(?-i:\h*)?((?:1[0-2]|[1-9]):(?:[0-5]\d):?(?:[0-5]\d)?(?-i:\h*)(?i:[ap]m?)|(?:[01]?\d|2[0-3]):(?:[0-5]\d):?(?:[0-5]\d)?)$" Local $aTestDateTime = StringRegExp($sTestDateTime, $sRegEx, 1) If @error Then Return SetError(1, 1, False) Local $sTestDate = $aTestDateTime[0] Local $sTestTime = $aTestDateTime[1] Local $aStartDateTime = StringRegExp($sStartDateTime, $sRegEx, 1) If @error Then Return SetError(1, 2, False) Local $sStartDate = $aStartDateTime[0] Local $sStartTime = $aStartDateTime[1] Local $aEndDateTime = StringRegExp($sEndDateTime, $sRegEx, 1) If @error Then Return SetError(1, 3, False) Local $sEndDate = $aEndDateTime[0] Local $sEndTime = $aEndDateTime[1] Select Case $sTestDate = "" And $sStartDate = "" And $sEndDate = "" $sTestDate = _NowCalcDate() $sStartDate = $sTestDate $sEndDate = $sTestDate Case $sTestDate <> "" And $sStartDate <> "" And $sEndDate <> "" Case $sTestDate = "" And $sStartDate <> "" And $sEndDate <> "" ContinueCase Case $sTestDate <> "" And $sStartDate = "" And $sEndDate <> "" ContinueCase Case $sTestDate <> "" And $sStartDate <> "" And $sEndDate = "" ContinueCase Case Else Return SetError(1, 4, False) EndSelect If _IsStandardDate($sTestDate) Then $sTestDate = _DateStandardToCalcDate($sTestDate) If @error Then Return SetError(2, 1, False) EndIf If _IsStandardDate($sStartDate) Then $sStartDate = _DateStandardToCalcDate($sStartDate) If @error Then Return SetError(2, 2, False) EndIf If _IsStandardDate($sEndDate) Then $sEndDate = _DateStandardToCalcDate($sEndDate) If @error Then Return SetError(2, 3, False) EndIf If Not _IsCalcDate($sTestDate) Then Return SetError(3, 1, False) If Not _IsCalcDate($sStartDate) Then Return SetError(3, 2, False) If Not _IsCalcDate($sEndDate) Then Return SetError(3, 3, False) $sTestDate = $sTestDate & " " $sStartDate = $sStartDate & " " $sEndDate = $sEndDate & " " If _IsTime12Hr($sTestTime) Then $sTestTime = _Time12HrTo24Hr($sTestTime) If @error Then Return SetError(2, 4, False) EndIf If _IsTime12Hr($sStartTime) Then $sStartTime = _Time12HrTo24Hr($sStartTime) If @error Then Return SetError(2, 5, False) EndIf If _IsTime12Hr($sEndTime) Then $sEndTime = _Time12HrTo24Hr($sEndTime) If @error Then Return SetError(2, 6, False) EndIf If Not _IsTime24Hr($sTestTime) Then Return SetError(3, 4, False) If Not _IsTime24Hr($sStartTime) Then Return SetError(3, 5, False) If Not _IsTime24Hr($sEndTime) Then Return SetError(3, 6, False) $sTestDateTime = $sTestDate & $sTestTime $sStartDateTime = $sStartDate & $sStartTime $sEndDateTime = $sEndDate & $sEndTime Local $sStartTestDateTimeDiff = _DateDiff("s", $sStartDateTime, $sTestDateTime) Switch @error Case 2 Return SetError(5, @error, False) Case 3 Return SetError(4, @error, False) EndSwitch Local $sEndTestDateTimeDiff = _DateDiff("s", $sTestDateTime, $sEndDateTime) Switch @error Case 2 Return SetError(4, @error, False) Case 3 Return SetError(6, @error, False) EndSwitch If $sStartTestDateTimeDiff >= 0 And $sEndTestDateTimeDiff >= 0 Then Return True Return False EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IsBetweenDatesTimesLite ; Description ...: Test a time to see if it is between the Start Date and Time and the End Date and Time. ; Syntax ........: _IsBetweenDatesTimesLite($sTestDateTime, $sStartDateTime, $sEndDateTime) ; Parameters ....: $sTestDateTime - A string value, Date and Time to test, in 24 hr format "YYYY/MM/DD[ HH:MM:SS]". ; $sStartDateTime - A string value, Start Date and Time, must be before End Date and Time in 24 hr format "YYYY/MM/DD[ HH:MM:SS]". ; $sEndDateTime - A string value, End Date and Time, must be after Start Date and Time in 24 hr format "YYYY/MM/DD[ HH:MM:SS]". ; Return values .: Success - True ; Failure - False, sets @error to: ; |1 - Invalid sTestDateTime. ; |2 - Invalid $sStartDateTime. ; |3 - Invalid $sEndDateTime. ; Author ........: Adam Lawrence (AdamUL) ; Modified ......: ; Remarks .......: Faster return than the _IsBetweenDatesTimes function, but more retricted on the format of the date and time entered. ; Related .......: _IsBetweenDatesTimes, _IsBetweenTimes ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _IsBetweenDatesTimesLite($sTestDateTime, $sStartDateTime, $sEndDateTime) Local $sStartTestDateTimeDiff = _DateDiff("s", $sStartDateTime, $sTestDateTime) Switch @error Case 2 Return SetError(2, @error, False) Case 3 Return SetError(1, @error, False) EndSwitch Local $sEndTestDateTimeDiff = _DateDiff("s", $sTestDateTime, $sEndDateTime) Switch @error Case 2 Return SetError(1, @error, False) Case 3 Return SetError(3, @error, False) EndSwitch If $sStartTestDateTimeDiff >= 0 And $sEndTestDateTimeDiff >= 0 Then Return True Return False EndFunc I hope others find this UDF useful. In response to BrewManNH suggestion about date formats, here are some functions created by guinness that could be useful to use with this UDF in relation to US/UK date format: _UKToUSDate() and _USToUKDate() Lupo73 updated and added a function to this thread, _DateTimeStandard, to convert date and time to a format than can be used with this UDF. Edit: Removed extra @error values listed in _Time12HrTo24Hr header. Edit 2: Corrected header for _IsBetweenDatesTimesLite for $sEndDateTime. Edit 3: Added link to guinness' _UKToUSDate() and _USToUKDate() functions. Edit 4: Added link to Lupo73's _DateTimeStandard function. Edit 5: Forum update stripped out in regexes, added file for download. Adam
    1 point
×
×
  • Create New...