Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/18/2017 in all areas

  1. New version - 17 Jun 23 ======================= Added: Added 24hr unpadded H mask. New UDF in zip below. Changelog: Changelog.txt Here is my version of a UDF to transform date/time formats. It is entirely self-contained and although it defaults to English for the month/day names, you can set any other language very simply, even having different ones for the input and output. You need to provide a date/time string, a mask to tell the UDF what is in the string, and a second mask to format the output - the masks use the standard "yMdhmsT" characters. This is an example script showing some of the features: #include <Constants.au3> ; Only required for MsgBox constants #include "DTC.au3" Global $sIn_Date, $sOut_Date ; Basic format $sIn_Date = "13/08/02 18:30:15" $sOut_Date = _Date_Time_Convert($sIn_Date, "yy/MM/dd HH:mm:ss", "dddd, d MMMM yyyy at h:mm TT") MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date) ; Note how day name is corrected $sIn_Date = "2013082 Sun 12:15:45 PM" $sOut_Date = _Date_Time_Convert($sIn_Date, "yyyyMMd ddd hh:mm:ss TT", "dddd, dd MMM yy") MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date) ; Note use of $i19_20 parameter to change century $sIn_Date = "13/08/02 18:30:15" $sOut_Date = _Date_Time_Convert($sIn_Date, "yy/MM/dd HH:mm:ss", "dddd, d MMMM yyyy at h:mm TT", 10) MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date) $sIn_Date = "18:30:15 13/08/02" $sOut_Date = _Date_Time_Convert($sIn_Date, "HH:mm:ss yy/MM/dd", "h:mm TT on ddd d MMM yyyy") MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date) ; Just to show it works both ways $sIn_Date = "Friday, 2 August 2013 at 6:30 PM" $sOut_Date = _Date_Time_Convert($sIn_Date, "dddd, d MMMM yyyy at h:mm TT", "dd/MM/yy HH:mm") MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date) $sIn_Date = $sOut_Date $sOut_Date = _Date_Time_Convert($sIn_Date, "dd/MM/yy HH:mm", "dddd, d MMMM yyyy at h:mm TT") MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date) ; Note false returns for non-specified elements $sIn_Date = "6:15 P" $sOut_Date = _Date_Time_Convert($sIn_Date, "h:m T", "yy/MM/dd HH:mm:ss") MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date) ; Note use of "x" in place of actual spacing/punctuation $sIn_Date = "Sun 12:15:45 PM" $sOut_Date = _Date_Time_Convert($sIn_Date, "dddxhhxmmxssxTT", "dddd HH:mm") MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date) ; Output month/day strings changed to French _Date_Time_Convert_Set("smo", "jan,fév,mar,avr,mai,juin,juil,août,sept,oct,nov,déc") _Date_Time_Convert_Set("ldo", "dimanche,lundi,mardi,mercredi,jeudi,vendredi,samedi") _Date_Time_Convert_Set("SDO", 3) ; Each short name is first 3 chars of equivalent long name ; Note as only the short day names are required, they could have been set directly: ; _Date_Time_Convert_Set("sdo", "dim,lun,mar,mer,jeu,ven,sam") $sIn_Date = "20130716 Sun 12:15:45 PM" $sOut_Date = _Date_Time_Convert($sIn_Date, "yyyyMMd ddd hh:mm:ss TT", "ddd, d MMM yy") MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date) ; Output month/day strings changed to German _Date_Time_Convert_Set("smo", "Jan.,Feb.,März,Apr.,Mai,Juni,Juli,Aug.,Sept.,Okt.,Nov.,Dez.") _Date_Time_Convert_Set("ldo", "Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag") $sIn_Date = "20130716 Sun 12:15:45 PM" $sOut_Date = _Date_Time_Convert($sIn_Date, "yyyyMMd ddd hh:mm:ss TT", "dddd, d MMM yy") MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date) ; All strings reconverted to default English _Date_Time_Convert_Set() ; As shown here $sIn_Date = "20130716 Sun 12:15:45 PM" $sOut_Date = _Date_Time_Convert($sIn_Date, "yyyyMMd ddd hh:mm:ss TT", "ddd, d MMM yy") MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date) And here is the UDF and example in zip format: DTC.zip As always, happy for any comments. M23
    1 point
  2. I've made a library, based on AutoItObject UDF with the goal of implementing getter and setter functionality and make it possible to define new object properties in as few steps as possible. Thank you to @trancexx for getting me on the right track, and all users in Hooking into the IDispatch interface for the code to get me going. If I've forgotten to add credit, please let me know Example: #include "AutoItObject_Internal.au3" $myCar = IDispatch() $myCar.make = 'Ford' $myCar.model = 'Mustang' $myCar.year = 1969 $myCar.__defineGetter('DisplayCar', DisplayCar) Func DisplayCar($oThis) Return 'A Beautiful ' & $oThis.parent.year & ' ' & $oThis.parent.make & ' ' & $oThis.parent.model EndFunc MsgBox(0, "", $myCar.DisplayCar) More examples: https://github.com/genius257/AutoItObject-Internal/tree/master/Examples Version: 4.0.1 AutoItObject_Internal.au3 Documentation Edit2 (19th March 2017): First of all, sorry about the lack of updates on this project. I always start too many projects and end up ignoring old projects, if I run into problems ^^'. So I've started moving my AutoIt scripts to GitHub. I will still post the most recent script version here.
    1 point
  3. iamtheky, #include <Array.au3> Local $avArray[6][2] = [ _ ["String0", "SubString0"], _ ["String1", "SubString1"], _ ["String2", "SubString2"], _ ["String3", "SubString3"], _ ["String4", "SubString4"], _ ["String5", "SubString5"]] $search = "SubString3" StringRegExpReplace(_ArrayToString($avArray , ",," , 0 , 0 , ",,"), ',+(?=.*?,' & $search & '(?=,,|$))', "") Local $r[3] = [@extended, Floor($r[0]/UBound($avArray, 2)), $r[0]-$r[1]*UBound($avArray, 2)] Msgbox(0,"", "[" & $r[1] & "][" & $r[2] & "]")
    1 point
  4. Did you expect this: #include <Array.au3> Local $sTxt Local $aArray Local $aNumbers[10] = [":zero: ", ":one: ", ":two: ", ":three: ", ":four: ", ":five: ", ":six: ", ":seven: ", ":eight: ", ":nine: "] While 1 $sTxt = InputBox("Enter Text", "Enter Text to Convert to Blocks", "") If @error Then Exit ConsoleWrite("----" & $sTxt & "----------" & @CRLF) Dim $aArray[StringLen($sTxt)] For $iLoop = 0 To StringLen($sTxt) - 1 Step 1 $aArray[$iLoop] = AscW(StringRight(StringLeft($sTxt, $iLoop + 1), 1)) Next For $iLoop = 0 To UBound($aArray) - 1 ConsoleWrite("->" & ChrW($aArray[$iLoop]) & @CRLF) Switch Asc(ChrW($aArray[$iLoop])) Case 0 To 31, Asc('"'), Asc("%") To Asc(")"), Asc("+") To Asc("/"), Asc(":") To Asc(">"), Asc("@"), Asc("[") To Asc("`") ConsoleWrite("1" & @CRLF) $aArray[$iLoop] = Chr($aArray[$iLoop]) Case Asc(" ") ConsoleWrite("2" & @CRLF) $aArray[$iLoop] = " " Case Asc("!") ConsoleWrite("3" & @CRLF) $aArray[$iLoop] = Random(0, 1, 1) ? ":exclamation: " : ":grey_exclamation: " Case Asc("#") ConsoleWrite("4" & @CRLF) $aArray[$iLoop] = ":hash: " Case Asc("$") ConsoleWrite("5" & @CRLF) $aArray[$iLoop] = Random(0, 1, 1) ? ":heavy_dollar_sign: " : ":moneybag: " Case Asc("*") ConsoleWrite("6" & @CRLF) $aArray[$iLoop] = Random(0, 1, 1) ? ":asterisk: " : ":eight_spoked_asterisk: " Case Asc("?") ConsoleWrite("7" & @CRLF) $aArray[$iLoop] = Random(0, 1, 1) ? ":question: " : ":grey_question: " Case Asc("0") To Asc("9") ConsoleWrite("8" & @CRLF) $aArray[$iLoop] = $aNumbers[Chr($aArray[$iLoop])] Case Asc('A') To Asc('Z'), Asc('a') To Asc('z') ConsoleWrite("9" & @CRLF) If StringLower(ChrW($aArray[$iLoop])) = "a" Then $aArray[$iLoop] = Random(0, 1, 1) ? ":regional_indicator_a: " : ":a: " ElseIf StringLower(ChrW($aArray[$iLoop])) = "b" Then $aArray[$iLoop] = Random(0, 1, 1) ? ":regional_indicator_b: " : ":b: " ElseIf StringLower(ChrW($aArray[$iLoop])) = "i" Then $aArray[$iLoop] = Random(0, 1, 1) ? ":regional_indicator_i: " : ":information_source: " ElseIf StringLower(ChrW($aArray[$iLoop])) = "m" Then $aArray[$iLoop] = Random(0, 1, 1) ? ":regional_indicator_m: " : ":m: " ElseIf StringLower(ChrW($aArray[$iLoop])) = "o" Then $aArray[$iLoop] = Random(0, 1, 1) ? ":regional_indicator_o: " : ":o2: " ElseIf StringLower(ChrW($aArray[$iLoop])) = "p" Then $aArray[$iLoop] = Random(0, 1, 1) ? ":regional_indicator_p: " : ":parking: " Else $aArray[$iLoop] = ":regional_indicator_" & StringLower(Chr($aArray[$iLoop])) & ": " EndIf Case 128 To 255 ConsoleWrite("10" & @CRLF) $aArray[$iLoop] = Chr($aArray[$iLoop]) Case Else ConsoleWrite("Else Statement Executed" & @CRLF) $aArray[$iLoop] = ChrW($aArray[$iLoop]) EndSwitch Next _ArrayToClip($aArray, "") WEnd The ranges work only with numbers I guess. Jos
    1 point
  5. LOL @iamtheky - if its any consolation I am enjoying your various solutions.
    1 point
  6. Thanks! By the way, the actual UDF can be found in this post: (Linking it for convenience)
    1 point
  7. There may be better ways but if you look at the _ArraySearch function in the help file there is a 2D example. However, it asks you for a column to search. If you don't want to do it that way, you could modify that example and return a 2D array of row and column like this: #include <Array.au3> #include <MsgBoxConstants.au3> Local $avArray[6][2] = [ _ ["String0", "SubString0"], _ ["String1", "SubString1"], _ ["String2", "SubString2"], _ ["String3", "SubString3"], _ ["String4", "SubString4"], _ ["String5", "SubString5"]] _ArrayDisplay($avArray, "$avArray") For $a=0 to UBound($avArray)-1 $result=_ArraySearch($avArray, "String3", 0, 0, 0, 1, 1, $a) ; in this case looking for "String3" if $result <> 0 then Global $2Danswer[2]=[$result,$a] ; create 2d array with global scope to hold answer ExitLoop ;stop looping to preserve column number - global scope array populated with answer EndIf Next _ArrayDisplay($2Danswer)
    1 point
  8. You might have a look at this thread. For comparing 1D arrays the Scripting.Dictionary way is by far much faster
    1 point
  9. Seems an intermediate solution (in terms of effort) would be to sort the large array and then use _ArrayBinarySearch perhaps?
    1 point
  10. I'm a bit of an AutoIT novice, so excuse the lack of code examples. I think your problem depends on the relative sizes of the two arrays. If one of the arrays is small (2-10 items), then your method is quite effective, the problem will occur when the two arrays are of significant and similar sizes. If you have a couple of arrays holding 100 000 items each, then that becomes a very large comparison. You could improve things quite a bit by sorting the arrays first and then dividing them into manageable buckets of data. For example, if your stored data is alpanumeric then make 36 arrays, depending on the first letter of your data 0-9 a-z. Then you only have to compare your "a" bucket to your "a" bucket. The overhead of creating the buckets versus your simplistic search of the entire range will depend on the data... Any help? Edit: You don't need to split the smaller array into buckets, just the large one, then iterate the small one. Second Edit (sorry!): Obviously this can be more sophisticated, if you don't have a uniform data distribution, change your strategy - you want to try and make the buckets near uniform size.
    1 point
  11. Malkey

    Date Between Two Dates

    This example allows for different date formats and different date separators. Local $InBetweenDate = @YEAR & "/" & @MON & "/" & @MDAY ; "1/6/2017" Local $FirstDate = "4.5.2017" Local $LastDate = "11-12-2017" MsgBox(0, "Results", _ $InBetweenDate & " is " & _ (_IsDateBetween($InBetweenDate, $FirstDate, $LastDate, 0, 2) ? "" : "not") & _ " between " & $FirstDate & " and " & $LastDate & ".") ; $iFormatTestDate and $Format : 0 for input dates format "YYYY/MM/DD"; or, ; 1 for input dates format "MM/DD/YYYY"; or, ; 2 for input dates format "DD/MM/YYYY". ; Where date divider can be "/", "-", or ".". Func _IsDateBetween($TestDate, $StartDate, $EndDate, $iFormatTestDate = 0, $iFormat = 0) Local $aConvert[3] = [ _ "StringFormat('%s%02s%02s','\1', '\2', '\3')", _ ; "YYYY/[M]M/[D]D" to YYYYMMDD "StringFormat('%s%02s%02s','\3', '\1', '\2')", _ ; "[M]M/[D]D/YYYY" to YYYYMMDD "StringFormat('%s%02s%02s','\3', '\2', '\1')"] ; "[D]D/[M]M/YYYY" to YYYYMMDD Local $TDate = Execute(StringRegExpReplace($TestDate, "(\d+)[/\-\.](\d+)[/\-\.](\d+)", $aConvert[$iFormatTestDate])) Local $SDate = Execute(StringRegExpReplace($StartDate, "(\d+)[/\-\.](\d+)[/\-\.](\d+)", $aConvert[$iFormat])) Local $EDate = Execute(StringRegExpReplace($EndDate, "(\d+)[/\-\.](\d+)[/\-\.](\d+)", $aConvert[$iFormat])) ;ConsoleWrite($SDate & " " & $TDate & " " & $EDate & @CRLF) Return ($TDate > $SDate And $TDate < $EDate ? 1 : 0) EndFunc ;==>_IsDateBetween
    1 point
  12. Nice examples you made in github
    1 point
  13. Do you mean CSS ? If so you can try to look here:
    1 point
  14. Show us your code and the resulting output from running it in Scite.
    1 point
  15. Skysnake, I would do it like this: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> $hGUI = GUICreate("Test", 500, 500) $cCombo = GUICtrlCreateCombo("", 10, 10, 200, 200) $cLabel = GUICtrlCreateLabel("", 10, 100, 200, 20) ; Add files _GUICtrlComboBox_BeginUpdate($cCombo) _GUICtrlComboBox_AddDir($cCombo, @WindowsDir & "\*.exe") _GUICtrlComboBox_EndUpdate($cCombo) GUISetState() GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cCombo ; Use Autoit to do the hard work - this fires when the user makes a selection GUICtrlSetData($cLabel, GUICtrlRead($cCombo)) EndSwitch WEnd Func _Edit_Changed() ; Autocomplete the edit _GUICtrlComboBox_AutoComplete($cCombo) ; Change the label to match the autocompleted edit entry If GUICtrlRead($cLabel) <> GUICtrlRead($cCombo) Then GUICtrlSetData($cLabel, GUICtrlRead($cCombo)) EndIf EndFunc ;==>_Edit_Changed Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg If $lParam = GUICtrlGetHandle($cCombo) And BitShift($wParam, 16) = $CBN_EDITCHANGE Then ; Our combo edit content has changed _Edit_Changed() ; Action this function EndIf EndFunc A bit simpler - but not that dissimilar. M23
    1 point
  16. for all paragraphs : #include <Array.au3> Global $iFilePath = @ScriptDir & "\New Text Document (2).txt" Global $iFileContent = FileRead($iFilePath) Global $iArrayParagraphs = StringSplit($iFileContent, @CRLF & @CRLF & @CRLF, 1) For $x = 1 To $iArrayParagraphs[0] Local $iArrayLine = StringSplit($iArrayParagraphs[$x], @CRLF, 1) Local $Array3D[UBound($iArrayLine) + 1][3] For $i = 0 To UBound($iArrayLine) - 1 If StringStripWS($iArrayLine[$i], 8) <> "" Then Local $XXX = $iArrayLine[$i] While StringInStr($XXX, " " & " ") $XXX = StringReplace($XXX, " " & " ", " ") WEnd ConsoleWrite($XXX & @CRLF) Local $XNXX = StringSplit($XXX, " ", 2) If UBound($XNXX) > 2 Then $Array3D[$i][0] = $XNXX[0] $Array3D[$i][1] = $XNXX[1] $Array3D[$i][2] = $XNXX[2] EndIf EndIf Next _ArrayDisplay($Array3D) Next for 1 paragraphs : #include <Array.au3> Global $iFilePath = @ScriptDir & "\New Text Document (2).txt" Global $iArrayLine = FileReadToArray($iFilePath) Global $Array3D[UBound($iArrayLine) + 1][3] For $i = 0 To UBound($iArrayLine) - 1 If StringStripWS($iArrayLine[$i], 8) <> "" Then Local $XXX = $iArrayLine[$i] While StringInStr($XXX, " " & " ") $XXX = StringReplace($XXX, " " & " ", " ") WEnd ConsoleWrite($XXX & @CRLF) Local $XNXX = StringSplit($XXX, " ", 2) If UBound($XNXX) > 2 Then $Array3D[$i][0] = $XNXX[0] $Array3D[$i][1] = $XNXX[1] $Array3D[$i][2] = $XNXX[2] EndIf EndIf Next _ArrayDisplay($Array3D)
    1 point
  17. Another nice (and powerfull) working example giving the start for some dot syntax and making use of the iCustomQueryInterface introduced in V4 of .NET No need this way to use regasm or invokemember logic (at least not in AutoIt coding, in the class logic that has to be enhanced) References https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.icustomqueryinterface(v=vs.110).aspx https://blogs.msdn.microsoft.com/jmstall/2009/07/09/icustomqueryinterface-and-clr-v4/ Source from stackflow fixed and example in AU3 https://stackoverflow.com/questions/26459041/implement-idispatch-with-using-icustomqueryinterface-set-property-not-working Doing QueryInterface/IDispatch managed looks a little easier then the unmanaged way script.au3 #include ".\Includes\CLR.au3" _Example() Func _Example() Local $oAssDynamic = _CLR_LoadLibrary("System.Dynamic") local $strSource=FileRead("echo.cs") ;~ consolewrite($strSource) Local $oAssemblyCSharp = _CLR_CompileCSharp($strSource,"System.dll|System.Core.dll|System.Dynamic.Dll|Microsoft.CSharp.dll") If IsObj($oAssemblyCSharp ) Then ConsoleWrite("$oAssembly: " & IsObj($oAssemblyCSharp) & @CRLF) local $oecho = _CLR_CreateObject($oAssemblyCSharp, "EchoProject.Echo") if isobj($oecho) Then consolewrite("echo object created " & @CRLF) ;~ var echo = new ActiveXObject("EchoProject.Echo"); consolewrite("Begin debug" & @CRLF); consolewrite($oecho.foo() & @CRLF); //foo consolewrite($oecho.bar & @CRLF); //bar $oecho.baz = "value"; consolewrite($oecho.baz & @CRLF); EndIf end function echo.cs //https://stackoverflow.com/questions/26459041/implement-idispatch-with-using-icustomqueryinterface-set-property-not-working using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; namespace EchoProject { [ComImport] [Guid("00020400-0000-0000-C000-000000000046")] [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] public interface IDispatch { void GetTypeInfoCount(out uint pctinfo); void GetTypeInfo(uint iTInfo, int lcid, out IntPtr info); void GetIDsOfNames( ref Guid iid, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 2)] string[] names, int cNames, int lcid, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I4, SizeParamIndex = 2)] int[] rgDispId); [PreserveSig] void Invoke( int dispId, ref Guid riid, int lcid, System.Runtime.InteropServices.ComTypes.INVOKEKIND wFlags, ref System.Runtime.InteropServices.ComTypes.DISPPARAMS pDispParams, [Out, MarshalAs(UnmanagedType.LPArray)] object[] result, IntPtr pExcepInfo, IntPtr puArgErr); } [ComVisible(true)] [ProgId("EchoProject.Echo")] [ClassInterface(ClassInterfaceType.None)] public class Echo : IDispatch, ICustomQueryInterface { private int lastDispId = 0; private Dictionary<int, string> dispIdNameMap = new Dictionary<int, string>(); public CustomQueryInterfaceResult GetInterface(ref Guid iid, out IntPtr ppv) { ppv = IntPtr.Zero; if (typeof(IDispatch).GUID == iid) { ppv = Marshal.GetComInterfaceForObject(this, typeof(IDispatch), CustomQueryInterfaceMode.Ignore); return CustomQueryInterfaceResult.Handled; } return CustomQueryInterfaceResult.NotHandled; } public void GetTypeInfoCount(out uint pctinfo) { pctinfo = 0; } public void GetTypeInfo(uint iTInfo, int lcid, out IntPtr info) { info = IntPtr.Zero; } public void GetIDsOfNames(ref Guid iid, string[] names, int cNames, int lcid, int[] rgDispId) { for (int i = 0; i < cNames; i++ ) { KeyValuePair<int, string> pair = dispIdNameMap.SingleOrDefault(p => p.Value == names[i]); if (pair.Key == 0) { dispIdNameMap.Add(++lastDispId, names[i]); rgDispId[i] = lastDispId; } else { //Assign the value rgDispId[i] = pair.Key; } } } public void Invoke(int dispId, ref Guid riid, int lcid, System.Runtime.InteropServices.ComTypes.INVOKEKIND wFlags, ref System.Runtime.InteropServices.ComTypes.DISPPARAMS pDispParams, [Out, MarshalAs(UnmanagedType.LPArray)] object[] result, IntPtr pExcepInfo, IntPtr puArgErr) { string name; bool retVal=dispIdNameMap.TryGetValue(dispId, out name); //if (result != null) //Console.WriteLine(dispId); //Console.WriteLine(name); if (retVal != false) { result[0] = name; } } } } Some other readings on the topic http://www.productiverage.com/idispatch-iwastedtimeonthis-but-ilearntlots
    1 point
×
×
  • Create New...