Jump to content

Search the Community

Showing results for tags 'DATE'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

  1. Newbie to _GUICtrlListView_RegisterSortCallBack and can't get it to sort properly on date in format MM/DD/YYYY. Example code below. Q - How do I get the date to sort properly? ;#AutoIt3Wrapper_run_debug_mode=Y #include <GUIConstantsEx.au3> #include <GuiListView.au3> Global $g_id_ListView Example() Exit Func Example() Local $idRow1, $idRow2, $idRow3 GUICreate("ListView Sort Question", 300, 200) $g_id_ListView = GUICtrlCreateListView("Row#|Name|Date", 10, 10, 280, 180) $id_Row1 = GUICtrlCreateListViewItem("#1|Alice|01/15/2022", $g_id_ListView) $id_Row2 = GUICtrlCreateListViewItem("#2|Bob|02/22/2021", $g_id_ListView) $id_Row3 = GUICtrlCreateListViewItem("#3|Carol|03/13/2021", $g_id_ListView) $id_Row10 = GUICtrlCreateListViewItem("#10|Dave|10/09/2021", $g_id_ListView) $id_Row11 = GUICtrlCreateListViewItem("#11|Eve|11/21/2021", $g_id_ListView) GUISetState(@SW_SHOW) ;$vCompareType = 0 ;not ok as Row# sort #1, #10, and want #1, #2, ;$vCompareType = 1 ;not ok as Row# sort #1, #10, and want #1, #2, $vCompareType = 2 ;Row# okay but Date messed up _GUICtrlListView_RegisterSortCallBack($g_id_ListView, $vCompareType) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $g_id_ListView ;MsgBox(0,"","col="&GUICtrlGetState($g_id_ListView)) _GUICtrlListView_SortItems($g_id_ListView, GUICtrlGetState($g_id_ListView)) EndSwitch WEnd _GUICtrlListView_UnRegisterSortCallBack($g_id_ListView) GUIDelete($g_id_ListView) EndFunc ;Func Example()
  2. it recomended to use the builten function _DateDiff hello autoit team i made a simple function to help me get the difference between to date i liked to share it with you the paramatrs of this function is firstdate and lastedate the two params is as the following year/month/day hours:minuts:seconds here is the function #include <date.au3> func _dateBetween($s_firstDate, $s_lastDate = default) if not (StringRegExp($s_firstDate, "((\d{4})\/(\d{2})\/(\d{2})\s(\d{2})\:(\d{2})\:(\d{2}))", 0) = 1) then Return SetError(1, 0, 0) if $s_lastDate = default then $s_lastDate = @year & "/" & @mon & "/" & @mday & " " & @hour & ":" & @min & ":" & @sec if not (StringRegExp($s_lastDate, "((\d{4})\/(\d{2})\/(\d{2})\s(\d{2})\:(\d{2})\:(\d{2}))", 0) = 1) then Return SetError(2, 0, 0) local $a_FirstSplitDate = StringSplit(StringRegExpReplace($s_firstDate, "((.*)\s(.*))", "$2"), "/", 2) local $a_FirstSplitTime = StringSplit(StringRegExpReplace($s_firstDate, "((.*)\s(.*))", "$3"), ":", 2) local $a_lastSplitDate = StringSplit(StringRegExpReplace($s_lastDate, "((.*)\s(.*))", "$2"), "/", 2) local $a_LastSplitTime = StringSplit(StringRegExpReplace($s_lastDate, "((.*)\s(.*))", "$3"), ":", 2) local $i_firstDateValue = _DateToDayValue($a_FirstSplitDate[0], $a_FirstSplitDate[1], $a_FirstSplitDate[2]) local $i_LastDateValue = _DateToDayValue($a_LastSplitDate[0], $a_LastSplitDate[1], $a_LastSplitDate[2]) if $i_firstDateValue > $i_LastDateValue then Return SetError(3, 0, 0) local $i_totalDays = $i_LastDateValue-$i_firstDateValue if not ($i_totalDays = 0) then if $a_FirstSplitTime[0] <= $a_lastSplitTime[0] then $i_totalDays += 1 $a_lastSplitTime[0] -= $a_FirstSplitTime[0] elseIf $a_FirstSplitTime[0] > $a_lastSplitTime[0] then if $i_totalDays > 0 then $i_totalDays -= 1 $a_FirstSplitTime[0] -= $a_lastSplitTime[0] endIf endIf endIf local $i_totalYears = 0 if $i_totalDays >= 365 then While $i_totalDays >= 365 $i_totalYears += 1 $i_totalDays -= 365 Wend endIf local $i_TotalMonths = 0 if $i_totalDays >= 30 then While $i_totalDays >= 30 $i_totalMonths += 1 $i_totalDays -= 30 Wend endIf local $i_totalWeeks = 0 if $i_totalDays >= 7 then While $i_totalDays >= 7 $i_totalWeeks += 1 $i_totalDays -= 7 Wend endIf $i_totalSeconds = ((($a_FirstSplitTime[0]*60)*60)+($a_FirstSplitTime[1]*60)+($a_FirstSplitTime[2]))-((($a_lastSplitTime[0]*60)*60)+($a_lastSplitTime[1]*60)+($a_LastSplitTime[2])) local $minus = "" if $i_totalSeconds < 0 then $minus = "-" $i_totalSeconds = StringReplace($i_totalSeconds, "-", "") endIf local $i_totalHours = 0 if $i_totalSeconds >= 3600 then While $i_totalSeconds >= 3600 $i_totalHours += 1 $i_totalSeconds -= 3600 Wend endIf local $i_totalminuts = 0 if $i_totalSeconds >= 60 then While $i_totalSeconds >= 60 $i_totalminuts += 1 $i_totalSeconds -= 60 Wend endIf local $a_arrayReturn[7] $a_arrayReturn[0] = $i_totalYears $a_arrayReturn[1] = $i_totalMonths $a_arrayReturn[2] = $i_totalWeeks $a_arrayReturn[3] = $i_totalDays $a_arrayReturn[4] = $minus & $i_totalHours $a_arrayReturn[5] = $minus & $i_totalminuts $a_arrayReturn[6] = $minus & $i_totalSeconds return $a_arrayReturn endFunc here is an example $a_calc = _dateBetween("2015/02/12 23:00:05", "2030/02/12 23:25:50") msgBox(64, "result", StringFormat("the difference is : %i years and %i months and %i weeks and %i days and %i hours and %i minuts and %i seconds", $a_calc[0], $a_calc[1], $a_calc[2], $a_calc[3], $a_calc[4], $a_calc[5], $a_calc[6])) am waiting for your comments with my greetings
  3. Hi All, Please help me on how to fetch date/time of last windows 10 system restore point using autoit? Basically its about querying the last restore point.
  4. Hi everyone, I am bit stumped as to why I am not able to set the time in the Date control #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm:ss" GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ; Set time Local $iRet = GUICtrlSetData($idDate, '13:33:37') ConsoleWrite('GUICtrlSetData returned ' & ($iRet = 1 ? 'success' : 'failure') & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example The documentation for GUICtrlSetData clearly mentions that it uses the same format as GUICtrlRead: But I get failure What gives? Thanks for the help in advance!
  5. I've encountered a problem with a single file where I cannot retrieve it's Date-time. So far my code has worked well for over 30 files, but this one is a mystery I cannot debug myself due to insufficient Au3 knowledge. In line 11 "_Date_Time_FileTimeToArray" is called and for this particular file it sets the @error to 10. I don't know what that error code means, but it's not set by the _Date functions themselves I think. Overall, it could be a problem caused by any of the functions below, how can I properly debug this? / Does anybody know a what's causing this? _WinAPI_CreateFile() / _Date_Time_GetFileTime() / _Date_Time_FileTimeToArray() Func _SetFileTimes($sFilePath) Local $monthNumber[13] = ["", "January", "February", "March", "April", "May", "Juny", "July", "August", "September", "October", "November", "December"] Local $dayNumber[7] = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] Local $fHandle = _WinAPI_CreateFile($sFilePath, 2, 2) ; read-only ; may NOT return a valid date for some reason! TODO Local $fTagFILETIME = _Date_Time_GetFileTime($fHandle) _WinAPI_CloseHandle($fHandle) ; This will return an empty array if theres no valid date $fModTime = _Date_Time_FileTimeToArray($fTagFILETIME[2]) ; last Modified if @error <> 10 then Local $year = $fModTime[2] Local $month = $fModTime[0] Local $day = $fModTime[1] Local $hour = $fModTime[3] Local $min = $fModTime[4] Local $sec = $fModTime[5] Local $ms = $fModTime[6] Local $weekday = $fModTime[7] Global $prettyTimestamp = StringFormat("%s, %s %d, %04d %02d:%02d:%02d", $dayNumber[$weekday], $monthNumber[$month], $day, $year, $hour, $min, $sec) Global $uploadDate = StringFormat("%04d-%02d-%02d", $year, $month, $day) $fModTime = _Date_Time_FileTimeToArray(_Date_Time_FileTimeToLocalFileTime($fTagFILETIME[2])) ; last Modified Local $year = $fModTime[2] Local $month = $fModTime[0] Local $day = $fModTime[1] Local $hour = $fModTime[3] Local $min = $fModTime[4] Local $sec = $fModTime[5] Local $ms = $fModTime[6] Local $weekday = $fModTime[7] ; GetUnixTime accounts for Local time, hence feed it local time Global $unixTimestamp = _GetUnixTime($year &"/"& $month &"/"& $day &" "& $hour&":"& $min &":"& $sec) else Global $prettyTimestamp = "N/A" Global $uploadDate = "" Global $unixTimestamp = "N/A" endif endfunc _GetUnixTime returned the year 1601 start date, showing that $fModTime is probably equal 0. (But Why?) The file reports these dates in Explorer, it's on local NTFS drive: Created: ‎‎Wednesday, ‎31. ‎Januar ‎2018, ‏‎18:55:02 Modified: ‎Wednesday, ‎10. ‎Januar ‎2018, ‏‎12:39:23 Accessed: ‎Wednesday, ‎10. ‎Januar ‎2018, ‏‎12:39:23
  6. Here is an other UDF for string handling : Date handling _StringDateConvert: convert a date from one format ("YMD", "MDY" or "DMY") to another. _StringIsDate: checks if a date with a given format is valid String management _StringCount: count of occurrences that appear in a string _StringFormatBytesSize: formatting a dimension expressed in bytes (bytes) in MB, TB, ...) _StringIsEndingWith: check if a string end with some characters _StringIsStartingWith: check if a string start with some characters _StringJoinArray: concatenate elements of an array to rebuild a string _StringPadLeft: filling a string with characters on the left _StringPadRight: fill a string with characters on the right _StringRemoveFrenchAccent: remove french accent _StringRemoveChars: deleting characters from a string _StringStrip: eliminate characters at the begin and/or at the end of a string _StringTitleCaseFrench: capitalize the first letter of each word with elimination of french accents _StringWSClean: simple replacement of "White Spaces", remove beginning and trailing spaces and multiple spaces removal Any comments, suggestions for improvement or constructive criticism are welcome. Below you will find the UDF and a demo program. JPD_String.zip
  7. Hey All, I'm trying to set the date using a variable. Basically, I set the date into the input box, then I change the input box, say, I change the year. Then I set what I typed into the input box into the Date Picker. This is a demo code. #include <ButtonConstants.au3> ;Start GUI includes #include <EditConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <GuiDateTimePicker.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 438, 192, 124) $Date1 = GUICtrlCreateDate("2019/02/02 23:16:26", 80, 64, 186, 21, $DTS_SHORTDATEFORMAT) $Input1 = GUICtrlCreateInput("Input1", 80, 152, 185, 21) $Button1 = GUICtrlCreateButton("Set data", 176, 96, 75, 25) $Button2 = GUICtrlCreateButton("Read from input", 176, 200, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $Read = GUICtrlRead($Date1) GUICtrlSetData($Input1, $Read) MsgBox(-1, "", $Read) Case $Button2 $Read = GUICtrlRead($Input1) $New_date = StringReplace($Read, "/", "") $DAY = StringLeft($New_date, 2) $MON = StringMid($New_date, 4, 3) $YEAR = StringRight($New_date, 4) MsgBox(-1, "", $DAY & $MON & $YEAR) ;_GUICtrlDTP_SetFormat($hWndDate, "yyyy/MM/dd") $DateFormate = ($DAY & " " & $MON & " " & $YEAR) $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW GUICtrlSendMsg($Date1, $DateFormate, 0, "MM/dd/yyyy") EndSwitch WEnd
  8. Hi, Ones(some times twice) a month I get an e-mail with zip file, which has price updates from a supplier. I have to upload the file to an FTP to get it processed. When uploading the file, it will get "timestamped" with the time and date at which time the file was uploaded. Normally this is fine, because I mostly upload the file the same day. Sometimes it may take 1 or 2 days before I can upload the file. For historical purpose, I would like to have the file timestamped with the original date. I have tried using: _FTP_Command ( $hFTPSession, "MFCT YYYYMMDDHHMMSS path") however this command does not work or change the timestamp as I expected. Does anyone now a way how I can change the timestamp of a FTP-file?
  9. So what i need is a function that I pass a starting date into and it counts up to the current date. Example: 2009-05-30 2009-05-31 2009-06-01 ... 2018-06-18 How would I do that? I found the Date.au3 in the includes but I can't find anything close to a time object like I'm used to working with in Java. I just need some $date = setDate(2009-05-30) and from there I could just add a day every time. I need this to be in the very format I stated earlier and from what I can see everytime related to date and time is automatically changed to my german locale. €: I already tried setDate but instead it changed my PCs clock. Not quite what i was looking for
  10. Hello I have a question please How to show Islamic date in Autoit I mean for example Ramadan month And moharam month ... etc I hope my question is clear for you Thanks in advance
  11. I have established how to get tomorrows date however I can't seem to figure out how to format the date into my required format of MM/DD/YYYY. I have this: $today=_DateToDayValue(@YEAR,@MON,@MDAY) Dim $Y, $M, $D $tomorrow=_DayValueToDate($today+1, $Y, $M, $D) The _DateToDayValue seems to have a fixed format. I've also tried a : $vardate = _DateAdd( 'd',1, _NowCalcDate()) with a "StringSplit" and/or StringFormat but the _NowCalcDate seems to also be fixed to a YYYY/MM/DD format. I'm sure I'm missing something simple but am at a loss. Any help would be MUCH appreciated
  12. So I get: $aMatch[0] Date(1499295600000) this is supposed to be 06 Jul 2017 $aMatch[0] Date(1483574400000) this is supposed to be 05 Jan 2017 does anybody know the formula to calculate the date from the large number? It doesn't seem to be anything to do with DateToDayValue. thanks in advance.
  13. I am taking a Date & Time and splitting them using _DateTimeSplit, so that I can create a filename in the format: YYYYMMDD_HHMMSS.jpg. The only issue is that if the month, or day, is a two-digit number that begins with a zero (so less than 10), then the month, or day, is formatted as a single-digit number. Suggestions on how to accomplish this? Example: 20180101 becomes 2018, 1, 1 20180303 becomes 2018, 3, 3 20180505 becomes 2018, 5, 5 20180606 becomes 2018, 6, 6 20180909 becomes 2018, 9, 9 What I want: 20180101 becomes 2018, 01, 01 20180303 becomes 2018, 03, 03 20180505 becomes 2018, 05, 05 20180606 becomes 2018, 06, 06 20180909 becomes 2018, 09, 09 Func _CreateFileNameFromDateTimeFormat($sDateThatWasChangedIntoDateTimeFormat = "2018/01/02 10:29:39") Local $aMyDate, $aMyTime, $sNewImageFileName _DateTimeSplit($sDateThatWasChangedIntoDateTimeFormat, $aMyDate, $aMyTime) _ArrayDisplay($aMyDate) _ArrayDisplay($aMyTime) ;This will become file name $sNewImageFileName = $aMyDate[1] & $aMyDate[2] & $aMyDate[3] & "_" & $aMyTime[1] & $aMyTime[2] & $aMyTime[3] & ".jpg" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sNewImageFileName = ' & $sNewImageFileName & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console EndFunc ;==>_CreateFileNameFromDateTimeFormat
  14. I've been looking through some different functions(not sure if that's the right word) to get the Date and time and I can't find one that doesn't include "/ " or ":" in what is returned. I'm trying to create a file name with this format "QuickConfig_MMDDYYYY_HHMM" (doesn't matter if 24 or 12hr format) #include <Date.au3> Func _SaveConfig MouseClick('primary',155, 46, 1, 0) ;clicks save as WinWait('Save bluePRINT Configuration As...','', 4) MouseClick('primary',632, 47, 1, 0) ;clicks the file path bar $Documents = @MyDocumentsDir $FilePath = $Documents & '\BP3 Configs' Send($FilePath) Send('{ENTER}') MouseClick('primary',166, 580, 1, 0) ;clicks file name bar $FileName = 'QuickConfig_' & _NowDate & '_' & _NowTime Send($FileName) Send('{ENTER}') EndFunc I'm wondering if there is a function somewhere to do this?
  15. I have date in the string format as "DD-MM-YYYY". I need to get yesterday's date from it. I tried converting this from _DateTimeFormat but not working. Is there any direct UDF available to get this.?
  16. In some systems the date is displayed in the Taskbar as 10-01-2018 And in some systems it is like, 1/10/2018 And in some it is, 10-Jan-2018 And in different formats. I wrote my code to convert 1/10/2018 to 10-01-2018 Func TodaysDate() $NewDate = _DateTimeFormat(_NowCalcDate(),1) $Array = StringSplit( $NewDate , ',' ) _ArrayDelete($Array, 0) _ArrayDelete($Array, 0) $Array1 = StringSplit($Array[0],' ') RemoveEmptyArrayLines($Array1) ;Will return the present day's date with format dd-mmm-yyyy ;$Date = StringStripWS($Array1[2]&"-"&StringLeft($Array1[1], 3)&"-"&$Array[1], $STR_STRIPALL) $Date = StringStripWS($Array1[2]&"-"&changeDateformat(StringLeft($Array1[1], 3))&"-"&$Array[1], $STR_STRIPALL) return $Date EndFunc Func RemoveEmptyArrayLines(ByRef $arrLines) $intCount = 1 While $intCount < UBound($arrLines) $arrLines[$intCount] = StringStripWS($arrLines[$intCount],$STR_STRIPLEADING + $STR_STRIPTRAILING) If StringLen($arrLines[$intCount])=0 Then _ArrayDelete($arrLines, $intCount) $intCount = $intCount - 1 EndIf $intCount = $intCount + 1 WEnd EndFunc ;To convert mmm to mm format Func changeDateformat($sText) Local $sMsg = StringStripWS($sText, $STR_STRIPALL) Switch $sMsg Case "Jan" $sMsg = "01" Case "Feb" $sMsg = "02" Case "Mar" $sMsg = "03" Case "Apr" $sMsg = "04" Case "May" $sMsg = "05" Case "Jun" $sMsg = "06" Case "Jul" $sMsg = "07" Case "Aug" $sMsg = "08" Case "Sep" $sMsg = "09" Case "Oct" $sMsg = "10" Case "Nov" $sMsg = "11" Case "Dec" $sMsg = "12" EndSwitch return $sMsg EndFunc But again it will work on machines only with 1/10/2018. Is there any direct function which will give only in the format 10-01-2018, whatever the system settings is.? I tried all the arguments for _DateTimeFormat, but showing machine dependent settings only. Google given these two links in AutoIT but these are also for specific formats only,like mine. Please suggest.
  17. To get the current time stamp, I got the below code. #include <Date.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #RequireAdmin ; Under Vista the Windows API "SetSystemTime" may be rejected due to system security $td = _Date_Time_GetSystemTime() $td = _Date_Time_SystemTimeToDateTimeStr($td) $td = StringReplace($td, " ", "_") $td = StringReplace($td, ":", "_") MsgBox(0,"",$td) But it is not giving the date or time of the timezone where the system is there. Please suggestt
  18. When I tried the below code, I am getting the date in mm-dd-yyyy format. But I require dd-mm-yyyy format. Can anyone suggest how to do that. Func TodaysDate() return StringReplace(_DateTimeFormat(_NowCalc(), 2), "/", "-") EndFunc Earlier I tried dd-mmm-yyyy format and it is working with below code. Func TodaysDate() $NewDate = _DateTimeFormat(_NowCalcDate(),1) $Array = StringSplit( $NewDate , ',' ) _ArrayDelete($Array, 0) _ArrayDelete($Array, 0) $Array1 = StringSplit($Array[0],' ') RemoveEmptyArrayLines($Array1) $Date = StringStripWS($Array1[2]&"-"&StringLeft($Array1[1], 3)&"-"&$Array[1], $STR_STRIPALL) return $Date EndFunc Which is unnecessarily complicated I feel., the approach Now I need format of dd-mm-yyyy. Can anyone suggest how to do this.
  19. Hi guys, I have some code; which doesn't quite work. $dateStop = "11302015" $tDate = _Date_Time_GetSystemTime() $currentdatestring = _Date_Time_SystemTimeToDateStr($tDate) If $currentdatestring >= $dateStop Then MsgBox(0, "Expired", "Script has expired.") Exit EndIf Basically, I want to essentially put an expiry date on the script. Where in the example above, it is 30th November 2015. Sometimes it works, sometimes it doesn't. I may have the string wrong, I may have the code all wrong. I thought about using the macro @mon @year etc but it gets quite conditional. i.e. if its 2015, but October, or if its 2015 and Dec, or if its March 2016 etc. But simplicity is great. Any help would be awesome.
  20. Test instructions are easy. 1. Run the following code in post #46 2. Click the advanced tab 3. Select a start date and an end date 4. Put a tick in the checkbox where it says 'Include Days Of The Week' 5. Click the Okay button You should get an array with a column of dates in your local format and a second column with day names in your language. It has a current range limit of just under 89 years but this range can appear anywhere between the years 1601 and 9999. The code is untidy and unfinished, but I would still like to know if it works outside the UK. No extra includes are needed. If it works in China, that would make me happy. Latest version in post #46 https://www.autoitscript.com/forum/topic/184849-please-test-this-in-your-language-region/?do=findComment&comment=1327947 #include <Array.au3> #include <GUIConstants.au3> #include <GuiEdit.au3> #include <Misc.au3> #include <GuiTab.au3> #include <Date.au3> #include <APILocaleConstants.au3> #include <WinAPILocale.au3> ;#include <ArrayWorkshop.au3> ; required functions are already included in this demo NewTable() Func NewTable(); ($hParent, $idListView, $hListView) ; [missing parent window] Local $sTitle = "New Table", _ $iStyle = BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), _ $iExStyle = BitOR($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST), _ $iWidth = 250, _ $iHeight = 292 Local $hChild = GUICreate($sTitle, $iWidth, $iHeight, Default + 100, Default + 100); , $iStyle, $iExStyle, $hParent) Local $idTab = GUICtrlCreateTab(2, 2, $iWidth -2, $iHeight -32) GUICtrlCreateTabItem("Standard") GUICtrlCreateLabel("Table Dimensions", 14, 35, 120, 20) GUICtrlSetColor(-1, 0x008000) GUICtrlCreateLabel("Number Of Columns", 14, 60, 94, 18) Local $hStandardCols = GUICtrlCreateInput("0", 104 +14, 55, 50, 20, BitOR($WS_TABSTOP, $ES_CENTER, $ES_NUMBER)) GUICtrlSetFont(-1, 10) GUICtrlCreateLabel("Number Of Rows", 14, 83, 90, 18) Local $hStandardRows = GUICtrlCreateInput("0", 104 +14, 81, 50, 20, BitOR($WS_TABSTOP, $ES_CENTER, $ES_NUMBER)) GUICtrlSetFont(-1, 10) GUICtrlCreateLabel("Table Indices", 14, 114, 120, 20) GUICtrlSetColor(-1, 0x008000) Local $hIndices = GUICtrlCreateCheckbox(" Enumerate First Column", 14, 137, 160, 20) ; REMEMBER YES, SETTINGS NO Local $hPadding = GUICtrlCreateCheckbox(" Include Leading Zeros", 14, 161, 124, 20) ; REMEMBER YES, SETTINGS NO GUICtrlCreateTabItem("Advanced") GUICtrlCreateLabel("Column 1 = Date Range", 14, 35, 120, 20) GUICtrlSetColor(-1, 0x008000) GUICtrlCreateLabel("Start Date", 14, 35 +20, 100, 20) Local $idDate1 = GUICtrlCreateDate("", 14, 56 +20, 105, 20, $WS_TABSTOP) GUICtrlCreateLabel("End Date", $iWidth - 118, 35 +20, 100, 20) Local $idDate2 = GUICtrlCreateDate("", $iWidth - 118, 56 +20, 105, 20, BitOR($WS_TABSTOP, $DTS_RIGHTALIGN)) GUICtrlCreateLabel("Column 2 = Days Of The Week (Optional)", 14, 108, 220, 20) GUICtrlSetColor(-1, 0x008000) Local $hCheckBox = GUICtrlCreateCheckbox(" Include Days Of The Week ", 14, 128, 190, 20) ; REMEMBER YES, SETTINGS NO Local $hRadio1 = GUICtrlCreateRadio(" Use Short Name", 14, 151) Local $hRadio2 = GUICtrlCreateRadio(" Use Long Name", $iWidth - 118, 151) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetState($hRadio1, $GUI_DISABLE) ; check settings later GUICtrlSetState($hRadio2, $GUI_DISABLE) ; check settings later GUICtrlCreateLabel("Add More Columns", 14, 181, 222, 20) GUICtrlSetColor(-1, 0x008000) GUICtrlCreateLabel("Total Number Of Columns", 14, 182 +23, 129, 18) Local $hColNum = GUICtrlCreateInput("1", 130 +14, 182 +21, 50, 20, BitOR($WS_TABSTOP, $ES_CENTER, $ES_NUMBER)) ; REMEMBER YES, SETTINGS NO GUICtrlSetFont(-1, 10) GUICtrlCreateTabItem("") ; end tabitem definition Local $hCancel = GUICtrlCreateButton("Cancel", $iWidth -143, $iHeight -25, 66, 20) Local $hOkay = GUICtrlCreateButton("OK", $iWidth -69, $iHeight -25, 66, 20) GUISetState(@SW_SHOW) Local $msg2, $bDisable = True, $iMaxFields = 65000, $bStandardError = False, $iRows = 0, $iCols = 0, _ $sMonitorAdv = GUICtrlRead($idDate1) & GUICtrlRead($idDate2) & GUICtrlRead($hColNum), $sDate1, $sDate2, $sColsAdv, $iDiff, $bErrorAdv = False While 1 $msg2 = GUIGetMsg() If $msg2 = $hCancel Or $msg2 = $GUI_EVENT_CLOSE Then ExitLoop If BitAND(GUICtrlRead($hCheckBox), $GUI_CHECKED) == $GUI_CHECKED Then If $bDisable Then GUICtrlSetState($hRadio1, $GUI_ENABLE) GUICtrlSetState($hRadio2, $GUI_ENABLE) $bDisable = False EndIf ElseIf Not $bDisable Then GUICtrlSetState($hRadio1, $GUI_DISABLE) GUICtrlSetState($hRadio2, $GUI_DISABLE) $bDisable = True EndIf $sDate1 = GUICtrlRead($idDate1) $sDate2 = GUICtrlRead($idDate2) $sColsAdv = GUICtrlRead($hColNum) If $sDate1 & $sDate2 & $sColsAdv <> $sMonitorAdv Then $iDiff = DateRange(LocaleDateToYMD($sDate1), LocaleDateToYMD($sDate2)) ; _DateDiff() is too limited If $iDiff * $sColsAdv > $iMaxFields Then If Not $bErrorAdv Then GUICtrlSetBkColor($hColNum, 0xFFA090) $bErrorAdv = True EndIf ElseIf $bErrorAdv Then GUICtrlSetBkColor($hColNum, 0xFFFFFF) $bErrorAdv = False EndIf $sMonitorAdv = $sDate1 & $sDate2 & $sColsAdv EndIf $iCols = GUICtrlRead($hStandardCols) $iRows = GUICtrlRead($hStandardRows) If Not $iRows Then GUICtrlSetData($hStandardRows, 0) If Not $iCols Then GUICtrlSetData($hStandardCols, 0) If ControlGetFocus($hChild) <> "Edit2" And StringRegExp($iRows, '\A0+[1-9]') Then GUICtrlSetData($hStandardRows, StringRegExpReplace($iRows, '(\A0+)([1-9])(\d+)*', '$2$3')) If ControlGetFocus($hChild) <> "Edit1" And StringRegExp($iCols, '\A0+[1-9]') Then GUICtrlSetData($hStandardCols, StringRegExpReplace($iCols, '(\A0+)([1-9])(\d+)*', '$2$3')) If $iRows > $iMaxFields Or $iCols > $iMaxFields Or GUICtrlRead($hStandardRows) * GUICtrlRead($hStandardCols) > $iMaxFields Then If Not $bStandardError Then GUICtrlSetBkColor($hStandardRows, 0xFFA090) GUICtrlSetBkColor($hStandardCols, 0xFFA090) $bStandardError = True EndIf ElseIf $bStandardError Then GUICtrlSetBkColor($hStandardRows, 0xFFFFFF) GUICtrlSetBkColor($hStandardCols, 0xFFFFFF) $bStandardError = False EndIf $iCols = GUICtrlRead($hColNum) If ControlGetFocus($hChild) <> "Edit3" And StringRegExp($iCols, '\A0+[1-9]') Then GUICtrlSetData($hColNum, StringRegExpReplace($iCols, '(\A0+)([1-9])(\d+)*', '$2$3')) $iCols = GUICtrlRead($hColNum) If $iCols < 1 Then If BitAND(GUICtrlRead($hCheckBox), $GUI_CHECKED) == $GUI_CHECKED And ControlGetFocus($hChild) <> "Edit3" Then GUICtrlSetData($hColNum, 2) Else GUICtrlSetData($hColNum, 1) EndIf If ControlGetFocus($hChild) = "Edit3" Then _GUICtrlEdit_SetSel($hColNum, 0, -1) EndIf If BitAND(GUICtrlRead($hCheckBox), $GUI_CHECKED) == $GUI_CHECKED Then If $iCols < 2 And ControlGetFocus($hChild) <> "Edit3" Then If ControlGetFocus($hChild) = "Button3" Then While _IsPressed('01') Sleep(20) WEnd EndIf If BitAND(GUICtrlRead($hCheckBox), $GUI_CHECKED) == $GUI_CHECKED Then GUICtrlSetData($hColNum, 2) Else GUICtrlSetData($hColNum, 1) EndIf EndIf Else If $iCols < 1 Then GUICtrlSetData($hColNum, 1) If ControlGetFocus($hChild) = "Edit3" Then _GUICtrlEdit_SetSel($hColNum, 0, -1) EndIf EndIf If $msg2 = $hOkay Then If $bErrorAdv Then MsgBox(262160, "uh-uh!", "Out of Range") ContinueLoop EndIf Local $sDelim = '-' ; read from settings ??? [maybe] If _GUICtrlTab_GetCurFocus($idTab) = 1 Then Local $iName, $sFormat = Default ; read from settings [ini] If BitAND(GUICtrlRead($hCheckBox), $GUI_CHECKED) == $GUI_CHECKED Then $iName = (BitAND(GUICtrlRead($hRadio1), $GUI_CHECKED) == $GUI_CHECKED) ? 3 : 2 Else $iName = -1 EndIf ; $sStartDate, $sStopDate, $sDelim = Default, $sFormat = Default, $iDayName = -1) GetDateArray(GUICtrlRead($idDate1), GUICtrlRead($idDate2), $sDelim, $sFormat, $iName) ; US [, '$3-$5-$1']) EndIf EndIf WEnd GUIDelete($hChild) EndFunc ;==> NewTable Func LocaleDateToYMD($sDate, $sDelim = '/') Local $iID = _WinAPI_GetUserDefaultLCID(), _ $aDateSplit = StringRegExp(_WinAPI_GetLocaleInfo($iID, $LOCALE_SSHORTDATE), '\w+', 3), _ $vTest = True ; [floating variable] If IsArray($aDateSplit) And UBound($aDateSplit) = 3 Then For $i = 0 To 2 ; determine the locale ymd order If StringInStr($aDateSplit[$i], 'y') Then $aDateSplit[$i] = 1 ; year ElseIf StringInStr($aDateSplit[$i], 'm') Then $aDateSplit[$i] = 2 ; month ElseIf StringInStr($aDateSplit[$i], 'd') Then $aDateSplit[$i] = 3 ; day EndIf Next $vTest = $aDateSplit[0] & $aDateSplit[1] & $aDateSplit[2] If StringInStr($vTest, '1') And StringInStr($vTest, '2') And StringInStr($vTest, '3') Then $vTest = False ; success EndIf If $vTest Then ; failure with the previous method [both methods work on Win7 in the UK] Local $sLongDate = _WinAPI_GetDateFormat(0, 0, $DATE_LONGDATE) $aDateSplit = StringRegExp($sLongDate, '(*UCP)\w+', 3) If Not IsArray($aDateSplit) And UBound($aDateSplit) <> 3 Then Return SetError(1) ; undetermined error? For $i = 0 To 2 ; determine the locale ymd order If $aDateSplit[$i] = @YEAR Then ; hopefully this method will work for all international regions $aDateSplit[$i] = 1 ; year ElseIf $aDateSplit[$i] = _DateToMonth(@MON, $DMW_LOCALE_LONGNAME) Then $aDateSplit[$i] = 2 ; month Else $aDateSplit[$i] = 3 ; day EndIf Next $vTest = $aDateSplit[0] & $aDateSplit[1] & $aDateSplit[2] If Not (StringInStr($vTest, '1') And StringInStr($vTest, '2') And StringInStr($vTest, '3')) Then Return SetError(2) ; undetermined error? EndIf Local $iCount = 1, $sYMD = '' Do For $i = 0 To 2 If $aDateSplit[$i] = $iCount Then $sYMD &= '$'& ($i*2 +1) & ($iCount <> 3 ? $sDelim : '') $iCount += 1 ExitLoop EndIf Next Until $iCount = 4 Return StringRegExpReplace($sDate, '(\d+)(\D)(\d+)(\D)(\d+)', $sYMD) EndFunc Func GetDateArray($sStartDate, $sStopDate, $sDelim = Default, $sFormat = Default, $iDayName = -1) Local $iID = _WinAPI_GetUserDefaultLCID(), _ $aDateSplit = StringRegExp(_WinAPI_GetLocaleInfo($iID, $LOCALE_SSHORTDATE), '\w+', 3) If IsArray($aDateSplit) And UBound($aDateSplit) = 3 Then For $i = 0 To 2 ; determine the locale ymd order If StringInStr($aDateSplit[$i], 'y') Then $aDateSplit[$i] = 1 ; year ElseIf StringInStr($aDateSplit[$i], 'm') Then $aDateSplit[$i] = 2 ; month ElseIf StringInStr($aDateSplit[$i], 'd') Then $aDateSplit[$i] = 3 ; day EndIf Next Else ; let's try an alternative method [both methods work on Win7 in the UK] Local $sLongDate = _WinAPI_GetDateFormat(0, 0, $DATE_LONGDATE) $aDateSplit = StringRegExp($sLongDate, '(*UCP)\w+', 3) If Not IsArray($aDateSplit) And UBound($aDateSplit) <> 3 Then Return SetError(1) ; undetermined error? For $i = 0 To 2 ; determine the locale ymd order If $aDateSplit[$i] = @YEAR Then ; hopefully this method will work for all international regions $aDateSplit[$i] = 1 ; year ElseIf $aDateSplit[$i] = _DateToMonth(@MON, $DMW_LOCALE_LONGNAME) Then $aDateSplit[$i] = 2 ; month Else $aDateSplit[$i] = 3 ; day EndIf Next EndIf ; check the array contains numbers 1 to 3 Local $sTest = $aDateSplit[0] & $aDateSplit[1] & $aDateSplit[2] If Not (StringInStr($sTest, '1') And StringInStr($sTest, '2') And StringInStr($sTest, '3')) Then Return SetError(2) ; undetermined error? If $sDelim = Default Then $sDelim = StringRegExp($sStartDate, '\D+', 3)[0] Local $iCount = 1, $sYMD = '' Do For $i = 0 To 2 If $aDateSplit[$i] = $iCount Then $sYMD &= '$'& ($i*2 +1) & ($iCount <> 3 ? $sDelim : '') $iCount += 1 ExitLoop EndIf Next Until $iCount = 4 $sStartDate = StringRegExpReplace($sStartDate, '(\d+)(\D)(\d+)(\D)(\d+)', $sYMD) $sStopDate = StringRegExpReplace($sStopDate, '(\d+)(\D)(\d+)(\D)(\d+)', $sYMD) Local $vReverse = False If $sStartDate > $sStopDate Then $vReverse = $sStartDate $sStartDate = $sStopDate $sStopDate = $vReverse EndIf ; internal format = yyyy/mm/dd Local $iStartYear = Number(StringRegExp($sStartDate, '\d+', 3)[0]), $iStopYear = Number(StringRegExp($sStopDate, '\d+', 3)[0]) Local $aTimeLine[(($iStopYear - $iStartYear +1) *366)] $iCount = 0 For $iYear = $iStartYear To $iStopYear For $iMon = 1 To 12 Switch $iMon Case 1, 3, 5, 7, 8, 10, 12 For $iDay = 1 To 31 ; this section of code can be shortened $aTimeLine[$iCount] = $iYear & $sDelim & StringFormat('%02i', $iMon) & $sDelim & StringFormat('%02i', $iDay) If $aTimeLine[$iCount] = $sStopDate Then ExitLoop 3 $iCount += 1 Next Case 4, 6, 9, 11 For $iDay = 1 To 30 $aTimeLine[$iCount] = $iYear & $sDelim & StringFormat('%02i', $iMon) & $sDelim & StringFormat('%02i', $iDay) If $aTimeLine[$iCount] = $sStopDate Then ExitLoop 3 $iCount += 1 Next Case Else For $iDay = 1 To IsLeapYear($iYear) ? 29 : 28 $aTimeLine[$iCount] = $iYear & $sDelim & StringFormat('%02i', $iMon) & $sDelim & StringFormat('%02i', $iDay) If $aTimeLine[$iCount] = $sStopDate Then ExitLoop 3 $iCount += 1 Next EndSwitch Next Next ReDim $aTimeLine[$iCount +1] ; get rid of unused elements For $i = 0 To UBound($aTimeLine) -1 If $aTimeLine[$i] = $sStartDate Then _DeleteRegion($aTimeLine, 1, 0, $i) ExitLoop EndIf Next _Predim($aTimeLine, 2) ; add 2nd dimension ; adding a day name column only works for start dates up to christmas day 2999 [millennium bug], is it worth fixing? ==> [FIXED] If $iDayName <> -1 Then ; $iDayName set to -1 because _DateDayOfWeek() format values range from 0 to 3 ReDim $aTimeLine[UBound($aTimeLine)][2] Local $aNextDay, $iDayNum If $sStartDate <= ('2999' & $sDelim & '12' & $sDelim & '25') Then For $i = 0 To 6 If $i = UBound($aTimeLine) Then ExitLoop $aNextDay = StringRegExp($aTimeLine[$i][0], '\d+', 3) $iDayNum = _DateToDayOfWeek (Number($aNextDay[0]), Number($aNextDay[1]), Number($aNextDay[2])) $aTimeLine[$i][1] = _DateDayOfWeek($iDayNum, $iDayName) Next For $i = 7 To UBound($aTimeLine) -1 $aTimeLine[$i][1] = $aTimeLine[Mod($i, 7)][1] Next Else Local $aDayName[7] For $i = 25 To 31 $aNextDay = StringRegExp('2999/12/' & $i, '\d+', 3) $iDayNum = _DateToDayOfWeek (Number($aNextDay[0]), Number($aNextDay[1]), Number($aNextDay[2])) $aDayName[$i -25] = _DateDayOfWeek($iDayNum, $iDayName) Next Local $iDateDiff = DateRange('2999/12/25', StringReplace($aTimeLine[0][0], $sDelim, '/')) For $i = 0 to 6 If $i = UBound($aTimeLine) Then ExitLoop $aTimeLine[$i][1] = $aDayName[Mod($iDateDiff + $i -1, 7)] Next For $i = 7 To UBound($aTimeLine) -1 $aTimeLine[$i][1] = $aTimeLine[Mod($i, 7)][1] Next EndIf EndIf If $sFormat = Default Then ; [regexp pattern stored in ini or settings] $aDateSplit = StringRegExp($sYMD, '\d', 3) _Predim($aDateSplit, 2) ReDim $aDateSplit[3][2] $aDateSplit[0][1] = 1 $aDateSplit[1][1] = 3 $aDateSplit[2][1] = 5 _ArraySort($aDateSplit) $sFormat = '$' & $aDateSplit[0][1] & $sDelim & '$' & $aDateSplit[1][1] & $sDelim & '$' & $aDateSplit[2][1] EndIf For $i = 0 To UBound($aTimeLine) -1 $aTimeLine[$i][0] = StringRegExpReplace($aTimeLine[$i][0], '(\d+)(\D)(\d+)(\D)(\d+)', $sFormat) Next If $vReverse Then _ReverseArray($aTimeLine) _ArrayDisplay($aTimeLine) Return $aTimeLine EndFunc ;==> GetDateArray Func IsLeapYear($iYear) If Mod($iYear, 4) Then Return False ElseIf Mod($iYear, 100) Then Return True ElseIf Mod($iYear, 400) Then Return False Else Return True EndIf EndFunc ;==> IsLeapYear Func DateRange($sDate1, $sDate2) ; must be yyyy/mm/dd Local $vTemp If $sDate1 > $sDate2 Then $vTemp = $sDate1 $sDate1 = $sDate2 $sDate2 = $vTemp EndIf Local $aArray1 = StringRegExp($sDate1, '\d+', 3), $aArray2 = StringRegExp($sDate2, '\d+', 3) For $i = 0 To 2 $aArray1[$i] = Number($aArray1[$i]) $aArray2[$i] = Number($aArray2[$i]) Next Local $iCount = 0 For $i = $aArray1[0] +1 To $aArray2[0] -1 If Not IsLeapYear($i) Then $iCount += 365 Else $iCount += 366 EndIf Next Local $iFirstMonth = 0 Switch $aArray1[1] Case 1, 3, 5, 7, 8, 10, 12 $iFirstMonth = 32 - $aArray1[2] Case 4, 6, 9, 11 $iFirstMonth = 31 - $aArray1[2] Case Else $iFirstMonth = (IsLeapYear($aArray1[0]) ? 30 : 29) - $aArray1[2] EndSwitch If $aArray1[0] < $aArray2[0] Then $iCount += $iFirstMonth For $i = $aArray1[1] +1 to 12 Switch $i Case 1, 3, 5, 7, 8, 10, 12 $iCount += 31 Case 4, 6, 9, 11 $iCount += 30 Case Else $iCount += (IsLeapYear($aArray1[0]) ? 29 : 28) EndSwitch Next $iCount += $aArray2[2] ; add remaining days in final month If $aArray2[1] > 1 Then For $i = 1 To $aArray2[1] -1 Switch $i Case 1, 3, 5, 7, 8, 10, 12 $iCount += 31 Case 4, 6, 9, 11 $iCount += 30 Case Else $iCount += (IsLeapYear($aArray2[0]) ? 29 : 28) EndSwitch Next EndIf ElseIf $aArray1[1] < $aArray2[1] Then ; same year, different month $iCount += $iFirstMonth For $i = $aArray1[1] +1 to $aArray2[1] -1 Switch $i Case 1, 3, 5, 7, 8, 10, 12 $iCount += 31 Case 4, 6, 9, 11 $iCount += 30 Case Else $iCount += (IsLeapYear($aArray1[0]) ? 29 : 28) EndSwitch Next $iCount += $aArray2[2] Else ; same month and year $iCount = $aArray2[2] - $aArray1[2] +1 EndIf Return $iCount EndFunc ;==> DateRange ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Functions from ArrayWorkshop.au3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #Au3Stripper_Off Func _ReverseArray(ByRef $aArray, $iDimension = 1, $iStart = 0, $iEnd = -1) If Not IsArray($aArray) Or UBound($aArray, 0) > 9 Then Return SetError(1) ; not a valid array Local $aBound = __GetBounds($aArray) If @error Then Return SetError(2) ; array contains zero elements $iDimension = ($iDimension = Default) ? 1 : Int($iDimension) If $iDimension < 1 Or $iDimension > $aBound[0] Then Return SetError(3) ; dimension does not exist $iStart = ($iStart = Default) ? 0 : Int($iStart) If $iStart < 0 Or $iStart > $aBound[$iDimension] - 2 Then Return SetError(4) ; meaningless $iStart value $iEnd = ($iEnd = -1 Or $iEnd = Default) ? $aBound[$iDimension] - 1 : Int($iEnd) If $iEnd <= $iStart Or $iEnd >= $aBound[$iDimension] Then Return SetError(5) ; meaningless $iEnd value If $aBound[0] = 1 Then ___Reverse1D($aArray, $iStart, $iEnd) Else $aBound[$iDimension] = 1 Local $aRegion = ___NewArray($aBound) ; to store extracted regions For $i = 1 To $aBound[0] $aBound[$i] -= 1 Next Local $sIndices = __HiddenIndices($aBound[0], $iDimension), $fnFloodFill = __FloodFunc()[$aBound[0]], _ $sTransfer = '$aSource' & $sIndices ; array syntax While $iEnd > $iStart $fnFloodFill($aRegion, $aBound, $iDimension, 0, $iStart, $aArray, $sTransfer) ; extract the current start region $sTransfer = '$aTarget' & $sIndices $fnFloodFill($aArray, $aBound, $iDimension, $iStart, $iEnd, '', $sTransfer) ; overwrite the current start region $sTransfer = '$aSource' & $sIndices $fnFloodFill($aArray, $aBound, $iDimension, $iEnd, 0, $aRegion, $sTransfer) ; overwrite the current end region $iStart += 1 $iEnd -= 1 WEnd EndIf EndFunc ;==>_ReverseArray Func _DeleteRegion(ByRef $aArray, $iDimension = 1, $iSubIndex = 0, $iRange = 1) If Not IsArray($aArray) Then Return SetError(1) Local $aBound = __GetBounds($aArray) ; get the bounds of each dimension If @error Then Return SetError(4) ; $aArray must contain at least one element If $aBound[0] > 9 Then Return SetError(2) ; nine dimension limit $iDimension = ($iDimension = Default) ? 1 : Int($iDimension) If $iDimension > $aBound[0] Or $iDimension < 1 Then Return SetError(3) ; out of bounds dimension $iSubIndex = ($iSubIndex = Default) ? 0 : Int($iSubIndex) If $iSubIndex < 0 Or $iSubIndex > $aBound[$iDimension] - 1 Then Return SetError(5) ; sub-index does not exist in the dimension $iRange = ($iRange = Default) ? 1 : Int($iRange) If $iRange < 1 Then Return SetError(6) ; range must be greater than zero $iRange = ($iSubIndex + $iRange < $aBound[$iDimension]) ? $iRange : $aBound[$iDimension] - $iSubIndex ; corrects for overflow If $iRange = $aBound[$iDimension] Then Return SetError(6) ; deleting the whole region is not currently supported [give reason] $aBound[$iDimension] -= $iRange ; the size of the dimension in the new array If $aBound[0] = 1 Then For $iNext = $iSubIndex To $aBound[$iDimension] - 1 $aArray[$iNext] = $aArray[$iNext + $iRange] Next ReDim $aArray[$aBound[$iDimension]] Return EndIf Local $iMaxIndex = $aBound[$iDimension] - 1 For $i = 1 To $aBound[0] $aBound[$i] -= 1 Next $aBound[$iDimension] = 0 ; set to loop once [one region at a time] Local $iFrom, $sTransfer = '$aTarget' & __HiddenIndices($aBound[0], $iDimension), $fnFloodFill = __FloodFunc()[$aBound[0]] For $iNext = $iSubIndex To $iMaxIndex $iFrom = $iNext + $iRange $fnFloodFill($aArray, $aBound, $iDimension, $iNext, $iFrom, '', $sTransfer) ; overwrite the final [untouched] region Next $aBound[$iDimension] = $iMaxIndex For $i = 1 To $aBound[0] $aBound[$i] += 1 Next __ResetBounds($aArray, $aBound) ; delete remaining indices EndFunc ;==>_DeleteRegion Func _PreDim(ByRef $aArray, $iDimensions, $bPush = False) If Not IsArray($aArray) Then Return SetError(1) $iDimensions = Int($iDimensions) If $iDimensions < 1 Or $iDimensions > 9 Then Return SetError(2) Local $iPreDims = UBound($aArray, 0) ; current number of dimensions If $iPreDims = $iDimensions Then Return ; no change If $iPreDims > 9 Then Return SetError(3) ; too many dimensions Local $aBound = __GetBounds($aArray) ; get the size of each original dimension If @error Then Return SetError(4) ; $aArray must contain at least one element $aBound[0] = $iDimensions ; overwrite this value with the new number of dimensions Local $sTransfer = '[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]][$a[9]]' ; array syntax to be sent to the remote loop region If $bPush Then ; prefix dimensions, or delete from the left Local $iOffset = Abs($iDimensions - $iPreDims) If $iPreDims > $iDimensions Then ; lower dimensions get deleted For $i = 1 To $iDimensions ; shift elements to lower indices $aBound[$i] = $aBound[$i + $iOffset] Next $sTransfer = '$aSource' & StringLeft('[0][0][0][0][0][0][0][0]', $iOffset * 3) & StringLeft($sTransfer, $iDimensions * 7) Else ; lower dimensions are created ReDim $aBound[$iDimensions + 1] ; make space for more dimensions For $i = $iDimensions To $iOffset + 1 Step -1 ; shift elements to higher indices $aBound[$i] = $aBound[$i - $iOffset] Next For $i = 1 To $iOffset ; assign the size of each additional dimension [1][1][1]... etc... $aBound[$i] = 1 Next $sTransfer = '$aSource' & StringMid($sTransfer, 1 + $iOffset * 7, $iPreDims * 7) EndIf Else ; Default behaviour = append dimensions, or delete from the right ReDim $aBound[$iDimensions + 1] ; modify the number of dimensions [according to the new array] For $i = $iPreDims + 1 To $iDimensions ; assign the size of each new dimension ...[1][1][1] etc... $aBound[$i] = 1 Next $sTransfer = '$aSource' & StringLeft($sTransfer, $iPreDims * 7) EndIf ; add or remove dimensions Local $aNewArray = ___NewArray($aBound) For $i = 1 To $iDimensions $aBound[$i] -= 1 ; convert elements to the maximum index value within each dimension Next ; access the remote loop region Local $iSubIndex = 0, $aFloodFill = __FloodFunc() $aFloodFill[$iDimensions]($aNewArray, $aBound, 0, $iSubIndex, '', $aArray, $sTransfer) $aArray = $aNewArray EndFunc ;==>_PreDim Func __GetBounds($aArray, $iHypothetical = 0) Local $iMaxDim = UBound($aArray, 0) Local $aBound[($iHypothetical ? $iHypothetical : $iMaxDim) + 1] ; [or ==> Local $aBound[9]] $aBound[0] = $iMaxDim For $i = 1 To $iMaxDim $aBound[$i] = UBound($aArray, $i) If $aBound[$i] = 0 Then Return SetError(1) Next If $iHypothetical Then For $i = $iMaxDim + 1 To $iHypothetical $aBound[$i] = 1 ; imaginary dimensions Next EndIf Return $aBound EndFunc ;==>__GetBounds Func __HiddenIndices($iBound, $iDimension) Local $sSyntax = '' ; to access elements at their original indices For $i = 1 To $iBound If $i <> $iDimension Then $sSyntax &= '[$a[' & $i & ']]' ; default ==> '$aSource[$iFrom][$a[2]][$a[3]][$a[4]][$a[5]] etc...' Else $sSyntax &= '[$iFrom]' EndIf Next Return $sSyntax EndFunc ;==>__HiddenIndices Func ___NewArray($aBound) Switch $aBound[0] Case 1 Local $aArray[$aBound[1]] Case 2 Local $aArray[$aBound[1]][$aBound[2]] Case 3 Local $aArray[$aBound[1]][$aBound[2]][$aBound[3]] Case 4 Local $aArray[$aBound[1]][$aBound[2]][$aBound[3]][$aBound[4]] Case 5 Local $aArray[$aBound[1]][$aBound[2]][$aBound[3]][$aBound[4]][$aBound[5]] Case 6 Local $aArray[$aBound[1]][$aBound[2]][$aBound[3]][$aBound[4]][$aBound[5]][$aBound[6]] Case 7 Local $aArray[$aBound[1]][$aBound[2]][$aBound[3]][$aBound[4]][$aBound[5]][$aBound[6]][$aBound[7]] Case 8 Local $aArray[$aBound[1]][$aBound[2]][$aBound[3]][$aBound[4]][$aBound[5]][$aBound[6]][$aBound[7]][$aBound[8]] Case 9 Local $aArray[$aBound[1]][$aBound[2]][$aBound[3]][$aBound[4]][$aBound[5]][$aBound[6]][$aBound[7]][$aBound[8]][$aBound[9]] EndSwitch Return $aArray EndFunc ;==>___NewArray Func ___Reverse1D(ByRef $aArray, $iStart, $iStop) Local $vTemp While $iStop > $iStart $vTemp = $aArray[$iStart] $aArray[$iStart] = $aArray[$iStop] $aArray[$iStop] = $vTemp $iStart += 1 $iStop -= 1 WEnd EndFunc ;==>___Reverse1D Func __ResetBounds(ByRef $aArray, $aBound) Switch $aBound[0] Case 1 ReDim $aArray[$aBound[1]] Case 2 ReDim $aArray[$aBound[1]][$aBound[2]] Case 3 ReDim $aArray[$aBound[1]][$aBound[2]][$aBound[3]] Case 4 ReDim $aArray[$aBound[1]][$aBound[2]][$aBound[3]][$aBound[4]] Case 5 ReDim $aArray[$aBound[1]][$aBound[2]][$aBound[3]][$aBound[4]][$aBound[5]] Case 6 ReDim $aArray[$aBound[1]][$aBound[2]][$aBound[3]][$aBound[4]][$aBound[5]][$aBound[6]] Case 7 ReDim $aArray[$aBound[1]][$aBound[2]][$aBound[3]][$aBound[4]][$aBound[5]][$aBound[6]][$aBound[7]] Case 8 ReDim $aArray[$aBound[1]][$aBound[2]][$aBound[3]][$aBound[4]][$aBound[5]][$aBound[6]][$aBound[7]][$aBound[8]] Case 9 ReDim $aArray[$aBound[1]][$aBound[2]][$aBound[3]][$aBound[4]][$aBound[5]][$aBound[6]][$aBound[7]][$aBound[8]][$aBound[9]] EndSwitch EndFunc ;==>__ResetBounds Func __FloodFunc() ; [modified for this demo] Local $aFloodFunc = ['', ___Flood1D, ___Flood2D] ; , ___Flood3D, ___Flood4D, ___Flood5D, ___Flood6D, ___Flood7D, ___Flood8D, ___Flood9D] Return $aFloodFunc EndFunc ;==>__FloodFunc Func ___Flood1D(ByRef $aTarget, $aBound, $iDimension, $iSubIndex, $iFrom, $aSource, $sTransfer) ; [still experimental] #forceref $iDimension, $iFrom, $aSource ; $iDimension would normally not apply here (special case) Local $a[10] = ['', 0, 0, 0, 0, 0, 0, 0, 0, 0] ; loop iteration count [or indices of higher dimensions within the source array] For $a[1] = $iSubIndex To $aBound[1] ; from the start to the bounds of the 1st dimension (special case) ; only one operation is needed in this special case $aTarget[$a[1]] = Execute($sTransfer) ; hidden parameters may appear in the code being executed Next EndFunc ;==>___Flood1D Func ___Flood2D(ByRef $aTarget, $aBound, $iDimension, $iSubIndex, $iFrom, $aSource, $sTransfer) #forceref $iFrom, $aSource ; hidden parameters Local $a[10] = ['', 0, 0, 0, 0, 0, 0, 0, 0, 0] ; loop iteration count [or indices of higher dimensions within the source array] For $a[2] = 0 To $aBound[2] For $a[1] = 0 To $aBound[1] $a[$iDimension] = $iSubIndex ; override the iteration count (fast method) - $a[0] has no influence $aTarget[$a[1]][$a[2]] = Execute($sTransfer) ; hidden parameters may appear in the code being executed Next Next EndFunc ;==>___Flood2D #Au3Stripper_On
  21. Hello guys, i have a problem in this regex because its not groupping right. Look: (\d{1,2}\s?[\055|\056|\057|\134]\s?\d{1,2}(\s?[\055|\056|\057|\134]\s?\d{2,4})?) It checks for day or dayday, month or monthmonth, yearyear or yearyearyear+year. separated with or without space and the characters "\/.-" But, a problem! I tried to regex the date with or without the "separator + year" Eg: 05/05 or 05/05/05, but when i have 05/05/05, regex are separating 05/05 and /05 Iam using group "()" wrong? Need help here Thx adv! ~~EDIT: Script used: (from autoitscript.com/forum/topic/129697-split-string-by-regular-expression/#comment-901335) #include <Array.au3> Local $sString = ClipGet() ; Extract the delimiters $aDelim = StringRegExp($sString, '(\d{1,2}\s?[\055|\056|\057|\134]\s?\d{1,2}(\s?[\055|\056|\057|\134]\s?\d{2,4})?)', 3) ; Split the string on the delimiters $aParts = StringSplit(StringRegExpReplace($sString, '(\d{1,2}\s?[\055|\056|\057|\134]\s?\d{1,2}(\s?[\055|\056|\057|\134]\s?\d{2,4})?)', "$<SEPARATOR>$"), "$<SEPARATOR>$", 3) ; Add the delimter to the start of the part For $i = 0 To UBound($aParts) - 1 ;$aParts[$i + 1] = $aDelim[$i] & $aParts[$i + 1] Next ; Set the count $aParts[0] = UBound($aParts) ; Display the result _ArrayDisplay($aParts) _ArrayDisplay($aDelim) Results in array: (the array parts in all string is ok; but the string delimitator himself is getting separated in every string that have year together) String used as test: Cheers.
  22. I've created a simple script that opens the Snipping Tool; Selects the "Full Screen Snip" option; then closes the program, prompting a save. What I can't figure is how to name the file using the system date and time. Can anyone help? Run(@WindowsDir & '\system32\SnippingTool.exe') AutoItSetOption('MouseCoordMode', 0) Sleep(1) $hWnd= WinWait("Snipping Tool", "ToolBarWindow32", 1) WinActive($hWnd) MouseClick('primary', 84, 48, 1, 0) MouseClick('primary', 84, 140, 1, 0) WinClose("[Class:Microsoft-Windows-Tablet-SnipperEditor]") ControlClick("Snipping Tool", "", "Button1")
  23. I have another AutoIT script making a Log file Sample of Log file: 2016/08/22 12:44:18 > Process: [RUNNING] [ACTIVE] 2016/08/22 12:48:35 > Process: [WAS NOT RUNNING] 2016/08/22 13:40:00 > Process: [FAILED] 2016/08/22 14:01:10 > Process: [WAS NOT RUNNING] I am looping through the Log file for the word "FAILED" I then want to get all lines that have "FAILED" and get their TIME My Current code to get this far: If FileExists($fileLog) Then $contents = FileRead($fileLog) If @error Then MsgBox(0, 'File Error', $fileLog & ' could not be read.') Else For $i = 1 To _FileCountLines($fileLog) $result = StringInStr($contents,$search) If $result >= 1 Then $filteredLine = FileReadLine($fileLog,$i) If StringInStr($filteredLine,$search) Then ConsoleWrite($filteredLine & @CRLF) ; this gets me the results I want sans the time parse EndIf Else ConsoleWrite( $search & " not found!" & @CRLF) EndIf Next EndIf EndIf For this part: If StringInStr($filteredLine,$search) Then ConsoleWrite($filteredLine & @CRLF) ; this gets me the results I want sans the time parse EndIf OUTPUT: 2016/08/22 13:40:00 > Process: [FAILED] I dont understand how I read the time in that output? I have tried _DateTimeFormat - Dont think this applies Tried _DateDiff - I dont have a the date yet so this doesnt work Would love if someone could tell me if I am thinking is the wrong direction and possibly lead me down the correct path to light side of the force
  24. Hi to all My problem is how can I compare two dates if I have the following code: $date = _NowDate() $dateend = "10/12/2016" if $date > $dateend Then Exit EndIf It does not work well I guess it's because I'm comparing two strings not realy two dates. My idea would break the date into three numbers year, month and day and go comparing data as numbers. is this correct...? Thank's to all
  25. I am assigning the current time stamp to a variable $strtTime and holding the execution for 5 seconds with Sleep and calculating the current time stamp. Ideally, the _DateDiff should give 5 seconds as output as i gave the parameter as s.But it is giving zero 0. Any suggestions....! Global $startTime = _Date_Time_GetLocalTime() $startTime = _Date_Time_SystemTimeToDateTimeStr($startTime) Sleep(5000)     $tCur = _Date_Time_GetLocalTime()     $tCur = _Date_Time_SystemTimeToDateTimeStr($tCur) $iDateCalc = _DateDiff('s', $startTime, $tCur)     MsgBox(0,"$iDateCalc",$iDateCalc)     FileWrite ($QTPfile,CHr(34) & $tCur & CHr(34) & Chr(44) & """" & $iDateCalc & """,")
×
×
  • Create New...