Leaderboard
Popular Content
Showing content with the highest reputation on 09/28/2015 in all areas
-
Hi mates. Some weeks ago @Biatu Ask for getting drive letter from an Arc Path I got interestion in. so I make a google search and got nice explanation http://blogs.microsoft.co.il/pavely/2014/02/05/creating-a-winobj-like-tool/ So this day I got some free hour and I decided go to a nice date with AutoIt. After that nice meeting this came out. Basically I a Simple AutoIt WinObj(Just for View Name-Type-SymbolicLink, I did not implement Right Click as WinObj). ScreenShot: Icons can change because I wrote it over Windows 10 x86 (Icons are from some system Files...) AutoIt snippet. ;~ Written by Danyfirex 20/09/2015 ;~ Thanks to: ;~ http://blogs.microsoft.co.il/pavely/2014/02/05/creating-a-winobj-like-tool/ ;~ https://technet.microsoft.com/en-us/library/bb896657.aspx #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <WinAPI.au3> #include <GuiTreeView.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <GuiStatusBar.au3> #RequireAdmin Opt("GUIOnEventMode", 1) Opt("MustDeclareVars",1) Global $sPath = "\" Global Const $DIRECTORY_QUERY = 0x0001 Global Const $DIRECTORY_TRAVERSE = 0x0002 Global Const $sTagUNICODESTRING = "USHORT Length;USHORT MaximumLength;PTR Buffer;" Global Const $sTagOBJECT_ATTRIBUTES = "ULONG Length;HANDLE RootDirectory;PTR ObjectName;ULONG Attributes;PTR SecurityDescriptor;PTR SecurityQualityOfService" Global $oTree = 0, $g_hListView = 0, $hoTree = 0, $hMainItem = 0, $oBar = 0, $hGUI = 0, $hImage = 0 iniGUI() Func iniGUI() Local $iStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) $hGUI = GUICreate("AutoIt WinObj", 700, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") HotKeySet("{UP}", "_KeyEvent") HotKeySet("{DOWN}", "_KeyEvent") $g_hListView = _GUICtrlListView_Create($hGUI, "", 210, 5, 500 - 15, 500 - 10 - 20) _GUICtrlListView_SetExtendedListViewStyle($g_hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) $oTree = GUICtrlCreateTreeView(5, 5, 200, 500 - 10 - 20, $iStyle, $WS_EX_CLIENTEDGE) $hoTree = GUICtrlGetHandle($oTree) GUISetOnEvent($GUI_EVENT_PRIMARYUP, "_TreeViewClick") $hMainItem = _GUICtrlTreeView_Add($oTree, 0, "\", 0, 0) $oBar = _GUICtrlStatusBar_Create($hGUI) $hImage = _GUIImageList_Create(16, 16, 5, 3) _ImageListCreate() _GUICtrlListView_SetImageList($g_hListView, $hImage, 1) _GUICtrlTreeView_SetNormalImageList($oTree, $hImage) _GUICtrlListView_InsertColumn($g_hListView, 0, "Name", (500 - 15) / 3) _GUICtrlListView_InsertColumn($g_hListView, 1, "Type", (500 - 15) / 3) _GUICtrlListView_InsertColumn($g_hListView, 2, "SymLink", (500 - 15) / 3) GUISetState(@SW_SHOW) _GUICtrlTreeView_BeginUpdate($oTree) _FillTree("\") _FillListView("\") _GUICtrlTreeView_EndUpdate($oTree) While True Sleep(30) WEnd EndFunc ;==>Example Func _Exit() Exit EndFunc ;==>_Exit Func _ImageListCreate() _GUIImageList_Add($hImage, _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 3)) ;Folder _GUIImageList_Add($hImage, _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 77)) ;! _GUIImageList_Add($hImage, _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 263)) ;Link _GUIImageList_Add($hImage, _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 47)) ;locker _GUIImageList_Add($hImage, _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 12)) ;Chip _GUIImageList_Add($hImage, _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 15)) ;Device _GUIImageList_Add($hImage, _GUIImageList_AddIcon($hImage, @SystemDir & "\Taskmgr.exe", 2)) ;Gear _GUIImageList_Add($hImage, _GUIImageList_AddIcon($hImage, @WindowsDir & "\regedit.exe", 0)) ;Registry _GUIImageList_AddIcon($hImage, @SystemDir & "\pifmgr.dll", 31) ;semaphore _GUIImageList_AddIcon($hImage, _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 69)) ;Driver _GUIImageList_Add($hImage, _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 34)) ;WinStation _GUIImageList_Add($hImage, _GUIImageList_AddIcon($hImage, @SystemDir & "\wmploc.dll", 60)) ; Key EndFunc ;==>_ImageListCreate Func _KeyEvent() If WinActive($hGUI) Then If ControlGetFocus($hGUI) = "SysTreeView321" Then HotKeySet(@HotKeyPressed) Send(@HotKeyPressed) _TreeViewClick() HotKeySet(@HotKeyPressed, "_KeyEvent") Return EndIf EndIf HotKeySet(@HotKeyPressed) Send(@HotKeyPressed) HotKeySet(@HotKeyPressed, "_KeyEvent") EndFunc ;==>_KeyEvent Func _TreeViewClick() Local $aInfo = 0 If @HotKeyPressed Then If $sPath <> _GetPath(_GUICtrlTreeView_GetTree($oTree)) Then $sPath = _GetPath(_GUICtrlTreeView_GetTree($oTree)) _GUICtrlStatusBar_SetText($oBar, $sPath) _FillListView($sPath) EndIf Return 0 EndIf $aInfo = GUIGetCursorInfo() If $aInfo[4] = $oTree Then If _GUICtrlTreeView_HitTestItem($oTree, $aInfo[0], $aInfo[1]) Then If $sPath <> _GetPath(_GUICtrlTreeView_GetTree($hoTree)) Then $sPath = _GetPath(_GUICtrlTreeView_GetTree($hoTree)) ConsoleWrite($sPath & @CRLF) _GUICtrlStatusBar_SetText($oBar, $sPath) _FillListView($sPath) EndIf EndIf EndIf EndFunc ;==>_TreeViewClick Func _FillListView($sPath) Local $aObjects = 0 $aObjects = _GetObjects($sPath) Local $Count = 0 _ArraySort($aObjects) _ClearListView() If UBound($aObjects) Then For $i = 0 To UBound($aObjects) - 1 If $aObjects[$i][1] <> "Directory" Then _GUICtrlListView_AddItem($g_hListView, $aObjects[$i][0], _IconbyType($aObjects[$i][1])) _GUICtrlListView_AddSubItem($g_hListView, $Count, $aObjects[$i][1], 1) _GUICtrlListView_AddSubItem($g_hListView, $Count, $aObjects[$i][2], 2) $Count += 1 EndIf Next EndIf EndFunc ;==>_FillListView Func _IconbyType($sType) Local $iType = 0 Switch $sType Case 'Symboliclink' $iType = 2 Case 'Mutant' $iType = 3 Case 'Section' $iType = 4 Case 'Event' $iType = 1 Case 'Semaphore' $iType = 8 Case 'Device' $iType = 5 Case 'Session', 'Partition', 'Job', 'ALPC Port', 'Callback', 'Type', 'FilterConnectionPort' $iType = 6 Case 'WindowStation' $iType = 10 Case 'Driver' $iType = 9 Case 'KeyedEvent' $iType = 11 Case 'Key' $iType = 7 Case Else $iType = 6 EndSwitch Return $iType EndFunc ;==>_IconbyType Func _ClearListView() _GUICtrlListView_DeleteAllItems($g_hListView) EndFunc ;==>_ClearListView Func _FillTree($Wild, $hhandle = $hMainItem) Local $aObjects=0 Local $ih = 0 $Wild = StringReplace($Wild, "\\", "\") $aObjects = _GetObjects($Wild, "Directory") _ArraySort($aObjects) If UBound($aObjects) Then For $i = 0 To UBound($aObjects) - 1 $ih = _GUICtrlTreeView_AddChild($oTree, $hhandle, $aObjects[$i][0], 0, 0) _FillTree($Wild & "\" & $aObjects[$i][0], $ih) $ih = $hhandle Next EndIf EndFunc ;==>_FillTree Func _GetPath($sTreePath) Return StringReplace(StringReplace($sTreePath, "|", "\"), "\\", "\") EndFunc ;==>_GetPath Func _GetObjects($sSource = "\", $sFilter = "") Local $tNameSource = _tName($sSource) Local $tUnicodeString = _RtlInitUnicodeString($tNameSource) Local $pUnicodeString = DllStructGetPtr($tUnicodeString) Local $tObject_Attributes = _InitializeObjectAttributes($pUnicodeString) Local $pObject_Attributes = DllStructGetPtr($tObject_Attributes) Local $hDirectory = _NtOpenDirectoryObject($pObject_Attributes, BitOR($DIRECTORY_TRAVERSE, $DIRECTORY_QUERY)) Local $hhandle = 0 Local $tData = 0 Local $tName = 0 Local $tType = 0 Local $index = 0 Local $bytes = 0 Local $tBuffer = 0 Local $aArcName[0] Local $taName = 0 Local $tStr = 0 Local $tAttr = 0 Local $hLink = 0 Local $taTarget = 0 Local $tTarget = 0 Local $tSTarget = 0 $tBuffer = DllStructCreate("byte Data[32767]") Local $aRet = DllCall("Ntdll.dll", "LONG", "NtQueryDirectoryObject", "HANDLE", $hDirectory, "ptr", DllStructGetPtr($tBuffer), "ULONG", 32767, "BOOL", False, "BOOL", True, "ULONG*", 0, "ULONG*", 0) If @error Or $aRet[0] < 0 Then Return $index = $aRet[6] $bytes = $aRet[7] For $i = 0 To $index - 1 $tData = DllStructCreate($sTagUNICODESTRING & $sTagUNICODESTRING, DllStructGetPtr($tBuffer) + ($i * 16)) $tName = DllStructCreate("wchar wNameString[" & DllStructGetData($tData, 1) & "]", DllStructGetData($tData, 3)) $tType = DllStructCreate("wChar wTypeString[" & DllStructGetData($tData, 4) & "]", DllStructGetData($tData, 6)) $taName = _tName($tName.wNameString) $tStr = _RtlInitUnicodeString($taName) $tAttr = _InitializeObjectAttributes(DllStructGetPtr($tStr), 0, $hDirectory) $hLink = _NtOpenSymbolicLinkObject(DllStructGetPtr($tAttr), $GENERIC_READ) $taTarget = _tName("") $tTarget = _RtlInitUnicodeString($taTarget) $tTarget.MaximumLength = 512 _NtQuerySymbolicLinkObject($hLink, $tTarget) $tSTarget = DllStructCreate("wchar wString[" & DllStructGetData($tTarget, 1) & "]", DllStructGetData($tTarget, 3)) If $tType.wTypeString = $sFilter Or $sFilter = "" Then ReDim $aArcName[UBound($aArcName) + 1][3] $aArcName[UBound($aArcName) - 1][0] = $tName.wNameString $aArcName[UBound($aArcName) - 1][1] = $tType.wTypeString $aArcName[UBound($aArcName) - 1][2] = (IsDllStruct($tSTarget) = 1) ? $tSTarget.wString : "" ConsoleWrite(">" & $i + 1 & @TAB & $tName.wNameString & @TAB & $tType.wTypeString & @TAB & $aArcName[UBound($aArcName) - 1][2] & @CRLF) EndIf $tType = 0 $tName = 0 $tData = 0 $tSTarget = 0 _WinAPI_CloseHandle($hLink) Next Return $aArcName EndFunc ;==>_GetObjects Func _RtlInitUnicodeString($tSourceString) Local $tUnicodeString = DllStructCreate($sTagUNICODESTRING) DllCall("Ntdll.dll", "NONE", "RtlInitUnicodeString", "struct*", $tUnicodeString, "struct*", $tSourceString) If @error Then SetError(@error, 0, 0) Return $tUnicodeString EndFunc ;==>_RtlInitUnicodeString Func _tName($String) Local $t = DllStructCreate("wchar String[512]") DllStructSetData($t, 1, $String) Return $t EndFunc ;==>_tName Func _InitializeObjectAttributes($pObjectName, $ulAttributes = 0, $hRootDirectory = Null, $pSecurityDescriptor = Null) Local $tObject_Attributes = DllStructCreate($sTagOBJECT_ATTRIBUTES) DllStructSetData($tObject_Attributes, 1, DllStructGetSize($tObject_Attributes)) DllStructSetData($tObject_Attributes, 2, $hRootDirectory) DllStructSetData($tObject_Attributes, 3, $pObjectName) Return $tObject_Attributes EndFunc ;==>_InitializeObjectAttributes Func _NtQuerySymbolicLinkObject($hLinkHandle, $tLinkTarget) Local $aRet = DllCall("Ntdll.dll", "LONG", "NtQuerySymbolicLinkObject", "HANDLE", $hLinkHandle, "struct*", $tLinkTarget, "ULONG*", 0) If @error Then SetError(@error, 0, 0) If $aRet[0] <> 0 Then SetError(1, 0, 0) EndFunc ;==>_NtQuerySymbolicLinkObject Func _NtOpenDirectoryObject($pObjectAttr, $AccessMask) Local $aRet = DllCall("Ntdll.dll", "LONG", "NtOpenDirectoryObject", "HANDLE*", 0, "ULONG", $AccessMask, "PTR", $pObjectAttr) If @error Then SetError(@error, 0, 0) If $aRet[0] < 0 Or $aRet[1] = 0 Then SetError(1, 0, 0) Return $aRet[1] EndFunc ;==>_NtOpenDirectoryObject ;~ Retur hLink Func _NtOpenSymbolicLinkObject($pObjectAttr, $AccessMask) Local $aRet = DllCall("Ntdll.dll", "LONG", "NtOpenSymbolicLinkObject", "HANDLE*", 0, "ULONG", $AccessMask, "PTR", $pObjectAttr) If @error Then Return SetError(@error, 0, 0) If $aRet[0] < 0 Or $aRet[1] = 0 Then Return SetError(1, 0, 0) Return $aRet[1] EndFunc ;==>_NtOpenSymbolicLinkObject Saludos2 points
-
This is my modification of the editor based on SciTE 3.2.5.99. Too many changes are made. Added new plugins (.lua) and rewrited existing, added Toolbar and Sidebar, expanded main and context menu, and more... I will not list all the changes, just download and try it. I also want to say a big thank the staff of Ru-Board for the excellent work on the modification of the editor and writing great plugins (.lua). Compiler Wrapper (CW) - a new tool that is part of SciTE 3.2.5.99 and designed to replace the AutoItWrapper. CW only works with "pragma" directives and does not use "AutoIt3Wrapper" directives. CW differs from AutoItWrapper both externally and internally but has a similar logic. Here are some possibilities utility - more friendly GUI, all options of "pragma" directives are located in one window, the ability to add digital signature, and a simple way to add resources (.rcs and .res files). The current version of CW is compatible with AutoIt 3.3.10.x, 3.3.12.x, and 3.3.14.x. How to install? Unpack CW to Compiler Wrapper folder and copy it to your SciTE or SciTE\Tools directory. Note that if you download SciTE 3.2.5.99 then you need not do anything because CW is already installed in the package. Command lines for SciTE: #Command line for compilation command.compile.au3="$(SciteDefaultHome)\Compiler Wrapper\CW.exe" "$(FilePath)" /m:1 /c:0 command.compile.subsystem.au3=1 #Command line for building (without GUI) command.build.au3="$(SciteDefaultHome)\Compiler Wrapper\CW.exe" "$(FilePath)" /m:1 /c:0 /s:1 command.build.subsystem.$(au3)=1 #Command line for changing "pragma" options only command.90.au3="$(SciteDefaultHome)\Compiler Wrapper\CW.exe" "$(FilePath)" /m:2 command.name.90.au3=Compiler Options... command.shortcut.90.au3=Shift+F7 command.subsystem.90.au3=1 command.save.before.90.au3=1 Command lines for Windows Explorer context menu: ;Command line for compilation "C:\Program Files (x86)\SciTE\Tools\Compiler Wrapper\CW.exe" "%1" /m:0 /c:0 ;Command line for building (without GUI) "C:\Program Files (x86)\SciTE\Tools\Compiler Wrapper\CW.exe" "%1" /m:0 /c:0 /s:1 Screenshots Files to download You can download latest SciTE build on this page (bottom of the post) or by using the SciTE Updater.1 point
-
InputBox does not need GuiCtrlRead. You use $Input1 directly. Look at the helfile to see whatInputBox returns1 point
-
If I understand, in your example, you want the MsgBox appears if the content of exist.html is 1 ? Is it right ? In this case, Execute is what you need. $sContent = 'msgbox (64,"test","test")' Execute($sContent)1 point
-
I'm not sure to understand, but maybe this ? If $sState = "0" Then Execute(BinaryToString(InetRead("http://example.com/script-do.html")))1 point
-
Until you figure out how to solve the issue, and depending what is it that you want to do, consider using some other UDF that has no issues like this. My favorite would be WinHttp.au3.1 point
-
1 point
-
First thing you should do is stop posting images of your error messages, they're almost useless. Second thing you should do is download Scite4AuotIt3.exe and install it. Third, run Tidy.exe on the ImageSearch.au3 file because that error will go away after you do that.1 point
-
Don't send $inputName Send GuiCtrlRead($inputName)1 point
-
Timppa, Welcome to the AutoIt forums. The numbers you see are the ControlIDs of the inputs - you need to use GUICtrlRead to get the content of the control, look in the Help file to see how it is used. M231 point
-
I should have explained that the layout parameter has two values: zero (= default) and NOT zero. When the layout is not zero, the source data (or array) is concatenated to the right of the target data (or array) with additional columns, otherwise it appears below with rows added. #include <Array.au3> ; For _ArrayDisplay ; add cols (1D & 1D & 2D) Local $aC1 = ['H','W'], $aC2 = ['E','O'], $aC3 = [['L','L','O'],['R','L','D']] Local $aRet = _ArrConcat_Max2D($aC1, $aC2, 1) $aRet = _ArrConcat_Max2D($aRet, $aC3, 1) _ArrayDisplay($aRet) ; add rows (2D & 2D) Local $aR1 = [['H','E','L','L','O']], $aR2 = [['W','O','R','L','D','!']] $aRet = _ArrConcat_Max2D($aR1, $aR2) _ArrayDisplay($aRet) ; cols side by side (1D & 1D) Local $aC3 = ['H','E','L','L','O'], $aC4 = ['W','O','R','L','D'] $aRet = _ArrConcat_Max2D($aC3, $aC4, 1) _ArrayDisplay($aRet)1 point
-
j1 will send you a quotation for a new dev1 point
-
Send a certain amount of bytes
WannaBeGut reacted to jguinch for a topic
_StringRepeat ? Edit : On just this : Local $s = "a" Local $sNewString For $i = 1 To 12 $sNewString &= $s Next ConsoleWrite($sNewString)1 point -
Yes you can, but there is no question in your initial post and the images were missing. Any way: Do not post images but simply cut&paste the text into a code or quote box. In this case you need to find, download the proper include file and store it in the include directory. Jos1 point
-
Since my last post I made great progress debugging the port. I estimate from early test that there are more than 100 bugs to fix. I'll do this alone over the next days (because it basically involves compiling a thing, printing a hexdump and then sitting down with a calculator and a pencil to figure out what went wrong - I'm not kidding). When all of the old examples compile and all their checksums match the VBNET compiler, I'll create a folder structure and split the code into more reasonable chunks . In this process, I'll set up the wiki and the Doc directories. I assume I'll write a few examples of how I imagine the doc to look like and then we can start (building the doc and cleaning the code). I removed the doc team and downgraded the team member privileges, so that no accidental commits mess up the code. We're going for the fork-improve-pr way . Oh, and sorry @rjframe, I rewrote all your code but there were some improvements I copied ^^1 point
-
I looked at the ported code and it looks really impressive. When is the documentation going to be created? I would love to at least make one PR to this project.1 point
-
Something like this? #include <Array.au3> ; For _ArrayDisplay Local $aRet = _ArrConcat_Max2D("Hello", "World", 1) _ArrayDisplay($aRet) Local $a1 = [0,1,2] $aRet = _ArrConcat_Max2D($a1, $aRet) _ArrayDisplay($aRet) Local $a2 = [[3,4,5,6],[7,8],["A","B","C","D","E"],["F"]] $aRet = _ArrConcat_Max2D($aRet, $a2, 1) _ArrayDisplay($aRet) Func _ArrConcat_Max2D($aTarget, $aSource, $iLayout = 0) If Not IsArray($aTarget) Then Local $aTemp[1] = [$aTarget] $aTarget = $aTemp EndIf Local $iTgtD = Ubound($aTarget, 0) If $iTgtD > 2 Then Return SetError(1) If Not IsArray($aSource) Then Local $aTemp[1] = [$aSource] $aSource = $aTemp EndIf Local $iSrcD = Ubound($aSource, 0) If $iSrcD > 2 Then Return SetError(2) Local $a = UBound($aTarget), $b = $iTgtD = 1 ? 1 : UBound($aTarget, 2), _ $c = UBound($aSource), $d = $iSrcD = 1 ? 1 : UBound($aSource, 2) ; Determine the dimensions of the new array If $iLayout Then Local $aNew[($a > $c ? $a : $c)][$b + $d] Else Local $aNew[$a + $c][($b > $d ? $b : $d)] EndIf ; Add the contents of $aTarget If $iTgtD = 2 Then For $i = 0 To $a -1 For $j = 0 To $b -1 $aNew[$i][$j] = $aTarget[$i][$j] Next Next Else For $i = 0 To $a -1 $aNew[$i][0] = $aTarget[$i] Next EndIf ; Concatenate $aSource If $iLayout Then If $iSrcD = 2 Then For $i = 0 To $c -1 For $j = $b To $b + $d - 1 $aNew[$i][$j] = $aSource[$i][$j - $b] Next Next Else For $i = 0 To $c -1 $aNew[$i][$b] = $aSource[$i] Next EndIf Else If $iSrcD = 2 Then For $i = $a To $a + $c -1 For $j = 0 To $d - 1 $aNew[$i][$j] = $aSource[$i - $a][$j] Next Next Else For $i = $a To $a + $c - 1 $aNew[$i][0] = $aSource[$i - $a] Next EndIf EndIf Return $aNew EndFunc ; ==> _ArrConcat_Max2DAccepts any variable types that are not arrays of greater than 2 dimensions. Success always returns a 2D array.1 point
-
And for me it's definitely time for the triplet infusion/shower/bed Good night everybody1 point
-
UEZ has good eyes ! It's also possible (and faster) to use the 2nd loop to make the array uniq : #include <array.au3> $sString = "B|A|A|C|C|AB|DDD|BAAS|003|100|02" $a = StringSplit($sString, "|", 2) Local $b[UBound($a)][2] For $i = 0 To UBound($a) - 1 $b[$i][0] = $a[$i] $b[$i][1] = StringFormat("%010d", StringLen($a[$i])) &"_"& $a[$i] Next _ArraySort($b, 0, 0, 0, 1) Local $sPrevious, $iIndex = 0 For $i = 0 To UBound($b) - 1 If $b[$i][0] <> $sPrevious Then $sPrevious = $b[$i][0] $a[$iIndex] = $b[$i][0] $iIndex += 1 EndIf Next Redim $a[$iIndex] _ArrayDisplay($a)1 point
-
1 point
-
Your problem with RunWait, is that you cannot then use WinSetState. Unless you run it from a second exe.1 point
-
How to Sort a array by string length ?
Trong reacted to AspirinJunkie for a topic
For this kinds of problem the best approach is to use a sorting function where you can set a user defined comparison function. Because the most sorting algorithms compare two elements of the set for greater/lesser/equal. If you have such a dynamic sorting function it's easy to sort every kind of the data exactly how you wan't without thinking about the sorting himself. Here is an example for such a function for your case: #include <Array.au3> Global $sString = "B|A|A|C|C|AB|DDD|BAAS|003|100|02" Global $a_Array = StringSplit($sString, "|", 2) _ArrayDisplay($a_Array, "initial Array") _ArraySortFlexible($a_Array, cb_compareStringSizes) _ArrayDisplay($a_Array, "sorted Array") ; user defined comparison-function Func cb_compareStringSizes($a, $b) Local $1 = StringLen($a), $2 = StringLen($b) If $1 = $2 Then Return StringCompare($a,$b, 2) Return $1 > $2 ? 1 : -1 EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _ArraySortFlexible ; Description ...: sort an array with a user-defined sorting rule by choosing from Quicksort/Dual-Pivot-Quicksort/Insertion-Sort ; Syntax ........:_ArraySortFlexible(ByRef $a_Array, [$cb_Func = Default, [Const $i_Min = 0, [Const $i_Max = UBound($a_Array) - 1, [Const $b_MedianPivot = True, [Const $b_InsSort = True, [Const $d_SmallThreshold = 25, {Const $b_First = True}]]]]]]) ; Parameters ....: $a_Array - the array which should be sorted (by reference means direct manipulating of the array - no copy) ; $cb_Func - function variable points to a function of a form "[1|0|-1] function(value, value)" ; the function compares two values a,and b for a>b/a=b/a<b ; an example is the AutoIt-Function "StringCompare". ; If the default value is used this functions gets only a wrapper for the optimized _ArraySort()-function ; $i_Min - the start index for the sorting range in the array ; $i_Max - the end index for the sorting range in the array ; $b_MedianPivot - If True: pivot-element is median(first,last,middle) Else: pivot = list[Random] ; $b_InsSort - If True: if length(list) < $d_SmallThreshold then insertion sort is used instead of recursive quicksort ; $d_SmallThreshold - the threshold-value for $b_InsSort (value=15 determined empirical) ; {$b_First} - don't touch - for internal use only (checks if call is sub-call or user-call) ; Return values .: Success: True - array is sorted now ; Failure: False ; @error = 1: $a_Array is'nt an array ; 2: invalid value for $i_Min ; 3: invalid value for $i_Max ; 4: invalid combination of $i_Min and $i_Max ; 5: invalid value for $cb_Func ; Author ........: AspirinJunkie ; Related .......: __cb_NormalComparison(), __PartitionHoare, __ArrayDualPivotQuicksort ; Remarks .......: for sorting the quicksort-algorithm is used with hoare's algorithm for partitioning ; ================================================================================================= Func _ArraySortFlexible(ByRef $a_Array, $cb_Func = Default, Const $i_Min = 0, Const $i_Max = UBound($a_Array) - 1, Const $b_DualPivot = True, Const $b_MedianPivot = True, Const $b_InsSort = True, Const $d_SmallThreshold = 15, Const $b_First = True) If $b_First Then If $cb_Func = Default Then Return _ArraySort($a_Array, 0, 0, 0, 0, 1) ; error-handling: If Not IsArray($a_Array) Then Return SetError(1, 0, False) If Not IsInt($i_Min) Or $i_Min < 0 Then Return SetError(2, $i_Min, False) If Not IsInt($i_Max) Or $i_Max > UBound($a_Array) - 1 Then Return SetError(3, $i_Min, False) If $i_Min > $i_Max Then Return SetError(4, $i_Max - $i_Min, False) If Not IsFunc($cb_Func) Then Return SetError(5, 0, False) EndIf ; choose the sorting-algorithm: If $b_DualPivot Then ; Dual-Pivot-Quicksort __ArrayDualPivotQuicksort($a_Array, $cb_Func, $i_Min, $i_Max) ElseIf $b_InsSort And (($i_Max - $i_Min) < $d_SmallThreshold) Then ; insertion-sort: Local $t1, $t2 For $i = $i_Min + 1 To $i_Max $t1 = $a_Array[$i] For $j = $i - 1 To $i_Min Step -1 $t2 = $a_Array[$j] If $cb_Func($t1, $t2) <> -1 Then ExitLoop $a_Array[$j + 1] = $t2 Next $a_Array[$j + 1] = $t1 Next Else ; Quicksort: ; the pivot element which divides the list in two separate lists (values < pivot -> left list, values > pivot -> right list); here pivot=list[random] to minimize the probability of worst case. Other solution is median(iMin, iMiddle, iMax) Das Trennelement (alles was kleiner ist - links davon, alles was größer ist - rechts davon), Hier Random damit Worst-Case unwahrscheinlich wird If $b_MedianPivot Then ; pivot = median(iMin, iMiddle, iMax) Local Const $iMiddle = Floor(($i_Max + $i_Min) / 2) Local Const $a = $a_Array[$i_Min], $b = $a_Array[$i_Max], $c = $a_Array[$iMiddle] Local $p_Value = $cb_Func($a, $b) = 1 ? $cb_Func($a, $c) = 1 ? $cb_Func($c, $b) = 1 ? $c : $b : $a : $cb_Func($a, $c) = 1 ? $a : $cb_Func($c, $b) = 1 ? $b : $c ; = Median(a,b,c) Local $p_Index = $p_Value = $a ? $i_Min : $p_Value = $b ? $i_Max : $iMiddle ; = Index(p_Value) Else ; pivot=list[random] Local $p_Index = Random($i_Min, $i_Max, 1) Local $p_Value = $a_Array[$p_Index] EndIf Local $v_Temp ; move the pivot-element to the end of the array If $p_Index < $i_Max Then $a_Array[$p_Index] = $a_Array[$i_Max] $a_Array[$i_Max] = $p_Value EndIf Local $i = __PartitionHoare($a_Array, $i_Min, $i_Max, $p_Value, $cb_Func) ; sort the left list (if length > 1) : If $i_Min < $i - 1 Then _ArraySortFlexible($a_Array, $cb_Func, $i_Min, $i - 1, False, False) ; recursively sort the right list (if length > 1): If $i_Max > $i + 1 Then _ArraySortFlexible($a_Array, $cb_Func, $i + 1, $i_Max, False, False) EndIf Return True EndFunc ;==>_ArraySortFlexible ; #FUNCTION# ====================================================================================== ; Name ..........: __ArrayDualPivotQuicksort ; Description ...: sort an array with the Dual-Pivot-Quicksort from Vladimir Yaroslavskiy ; Syntax ........:__ArrayDualPivotQuicksort(ByRef $A, [$cb_Func = Default, [Const $left = 0, [Const $right = UBound($a_Array) - 1, Const $d_SmThr = 25, [Const $b_MedQuant = True, {Const $b_First = True}]]]]]) ; Parameters ....: $A - the array which should be sorted (by reference means direct manipulating of the array - no copy) ; $cb_Func - function variable points to a function of a form "[1|0|-1] function(value, value)" ; the function compares two values a,and b for a>b/a=b/a<b ; an example is the AutoIt-Function "StringCompare". ; If the default value is used this functions gets only a wrapper for the optimized _ArraySort()-function ; $left - the start index for the sorting range in the array ; $right - the end index for the sorting range in the array ; $div - factor for calculating the pivots positions - normally dont't change this value ; $d_SmThr - the threshold-value for $b_InsSort (value=35 determined empirical) ; $b_MedQuant - if true the dual-pivot-elements are estimated by an more robust approach which should lead to more similar sized subarrays ; {$b_First} - don't touch - for internal use only (checks if call is sub-call or user-call) ; Return values .: Success: True - array is sorted now ; Failure: False ; @error = 1: $a_Array is'nt an array ; 2: invalid value for $i_Min ; 3: invalid value for $i_Max ; 4: invalid combination of $i_Min and $i_Max ; 5: invalid value for $cb_Func ; Author ........: AspirinJunkie ; Related .......: __cb_NormalComparison() ; ================================================================================================= Func __ArrayDualPivotQuicksort(ByRef $a, $cb_Func = Default, Const $left = 0, Const $right = UBound($a) - 1, $div = 3, Const $d_SmThr = 47, Const $b_MedQuant = True, Const $b_First = True) Local $d_Len = $right - $left Local $k, $t, $N Local $t1, $t2 ; variables for insertion-sort If $b_First Then If $cb_Func = Default Then Return _ArraySort($a, 0, 0, 0, 0, 1) ; If $cb_Func = Default Then $cb_Func = __cb_NormalComparison ; error-handling: If Not IsArray($a) Then Return SetError(1, 0, False) If Not IsInt($left) Or $left < 0 Then Return SetError(2, $left, False) If Not IsInt($right) Or $right > UBound($a) - 1 Then Return SetError(3, $right, False) If $left >= $right Then Return SetError(4, $right - $left, False) If Not IsFunc($cb_Func) Then Return SetError(5, 0, False) EndIf ;~ ; Insertion-Sort if array is small enough: If $d_Len < $d_SmThr Then For $i = $left + 1 To $right $t1 = $a[$i] For $j = $i - 1 To $left Step -1 $t2 = $a[$j] If $cb_Func($t1, $t2) <> -1 Then ExitLoop $a[$j + 1] = $t2 Next $a[$j + 1] = $t1 Next Return True EndIf ; ------------ estimate the two pivot-elements -------------------------- If $b_MedQuant And $d_Len > $d_SmThr Then Local $d_third = Floor($d_Len / 3) ; Estimate the 25% / 75% -quantils better: Local $aMp[5] = [$left, Floor($left + $d_third), Floor($left + 0.5 * $d_Len), Floor($right - $d_third), $right] For $i = 1 To 4 ; insertion-sort for the quantils (sort the quartils also inside the array) (is like a 5-Point Double-Median for the 25%/75%-quantil) $t1 = $a[$aMp[$i]] For $j = $i - 1 To 0 Step -1 $t2 = $a[$aMp[$j]] If $cb_Func($t1, $t2) <> -1 Then ExitLoop $a[$aMp[$j + 1]] = $t2 Next $a[$aMp[$j + 1]] = $t1 Next Local $m1 = $aMp[1], $m2 = $aMp[3] Else Local $d_third = Floor($d_Len / $div) ;"medians" (at index 25% and 75%) Local $m1 = $left + $d_third Local $m2 = $right - $d_third If $m1 <= $left Then $m1 = $left + 1 If $m2 >= $right Then $m2 = $right - 1 EndIf ; ensure that m1 < m2 and move them to the outer fields If $cb_Func($a[$m1], $a[$m2]) = -1 Then __swap($a, $m1, $left) __swap($a, $m2, $right) Else __swap($a, $m1, $right) __swap($a, $m2, $left) EndIf ; pivots: Local $pivot1 = $a[$left] Local $pivot2 = $a[$right] ; pointers: Local $less = $left + 1 Local $great = $right - 1 ; sorting: $k = $less Do ; move elements < pivot1 to the beginning of the array If $cb_Func($a[$k], $pivot1) = -1 Then ; __swap($A, $k, $less) $t = $a[$k] $a[$k] = $a[$less] $a[$less] = $t $less += 1 ; move elements > pivot1 to the end of the array ElseIf $cb_Func($a[$k], $pivot2) = 1 Then While $k < $great And $cb_Func($a[$great], $pivot2) = 1 $great -= 1 WEnd ;__swap($A, $k, $great) $t = $a[$k] $a[$k] = $a[$great] $a[$great] = $t $great -= 1 If $cb_Func($a[$k], $pivot1) = -1 Then ;__swap($A, $k, $less) $t = $a[$k] $a[$k] = $a[$less] $a[$less] = $t $less += 1 EndIf EndIf $k += 1 Until $k > $great ; swaps Local $dist = $great - $less If $dist < 13 Then $div += 1 __swap($a, $less - 1, $left) __swap($a, $great + 1, $right) ; subarrays If ($less - 2 - $left) > 0 Then __ArrayDualPivotQuicksort($a, $cb_Func, $left, $less - 2, $div, $d_SmThr, $b_MedQuant, False) If ($right - ($great + 2)) > 0 Then __ArrayDualPivotQuicksort($a, $cb_Func, $great + 2, $right, $div, $d_SmThr, $b_MedQuant, False) ; equal elements If ($dist > ($d_Len - 13)) And ($cb_Func($pivot2, $pivot1) <> 0) Then $k = $less Do If $cb_Func($a[$k], $pivot1) = 0 Then ;__swap($A, $k, $less) $t = $a[$k] $a[$k] = $a[$less] $a[$less] = $t $less += 1 ElseIf $cb_Func($a[$k], $pivot2) = 0 Then ;__swap($A, $k, $great) $t = $a[$k] $a[$k] = $a[$great] $a[$great] = $t $great -= 1 If $cb_Func($a[$k], $pivot1) = 0 Then ;__swap($A, $k, $less) $t = $a[$k] $a[$k] = $a[$less] $a[$less] = $t $less += 1 EndIf EndIf $k += 1 Until $k > $great EndIf ; the middle subarray If $cb_Func($pivot1, $pivot2) = -1 And $great - $less > 0 Then __ArrayDualPivotQuicksort($a, $cb_Func, $less, $great, $div, $d_SmThr, $b_MedQuant, False) Return True EndFunc ;==>__ArrayDualPivotQuicksort ; #FUNCTION# ====================================================================================== ; Name ..........: __swap ; Description ...: helper function for swap two values inside an array ; Syntax ........: __swap(ByRef Const $a, ByRef Const $b) ; Parameters ....: $a - the array ; $i - index of value 1 ; $j - index of value 2 ; Return values .: - ; Author ........: AspirinJunkie ; ================================================================================================= Func __swap(ByRef $a, Const $i, Const $j) Local Const $t = $a[$i] $a[$i] = $a[$j] $a[$j] = $t EndFunc ;==>__swap ; #FUNCTION# ====================================================================================== ; Name ..........: __PartitionHoare ; Description ...: helper function for partitioning inside the quicksort-function ; there exists several algorithms for this. ; Syntax ........: __PartitionHoare(ByRef $a_Array, Const $i_Min, Const $i_Max, Const $p_Value, Const $cb_Func) ; Parameters ....: $a_Array - the array ; $i_Min - the start index for the partitioning range in the array ; $i_Max - the end index for the partitioning range in the array ; $p_Value - the value of the pivot-element ; $cb_Func - function variable points to a function of a form "[1|0|-1] function(value, value)" ; the function compares two values a,and b for a>b/a=b/a<b ; an example is the AutoIt-Function "StringCompare". ; Return values .: the position of the pivot-element ; Author ........: AspirinJunkie ; ================================================================================================= Func __PartitionHoare(ByRef $a_Array, Const $i_Min, Const $i_Max, Const $p_Value, Const $cb_Func) ; divide the array in two separate lists in dependency of the pivot-element ; there are several algorithms to reach this (here used: "Quickselect / Hoare's selection algorithm" - see "Lomuto's algorithm") Local $i = $i_Min - 1 Local $j = $i_Max + 1 Local $t Do ; start from right and go left until the next element which is smaller than pivot: Do $j -= 1 Until $cb_Func($a_Array[$j], $p_Value) = -1 Or $j = $i_Min ; start from left and go right until the next element which is greater than pivot: Do $i += 1 Until $cb_Func($a_Array[$i], $p_Value) = 1 Or $i = $i_Max ; swap if elements are on the wrong side of the lists If $i < $j Then $t = $a_Array[$j] $a_Array[$j] = $a_Array[$i] $a_Array[$i] = $t EndIf Until $i >= $j ; swap with pivot-element if pivot is at the wrong list-side: If $cb_Func($a_Array[$i], $p_Value) = 1 Then $a_Array[$i_Max] = $a_Array[$i] $a_Array[$i] = $p_Value EndIf Return $i EndFunc ;==>__PartitionHoare ; #FUNCTION# ====================================================================================== ; Name ..........: __cb_NormalComparison ; Description ...: helper function which provides a standard AutoIt-comparison for flexible sorting ; Syntax ........: __cb_NormalComparison(ByRef Const $a, ByRef Const $b) ; Parameters ....: $a - the first value ; $b - the second value ; Return values .: 1: a > b ; 0: a = b ; -1: a < b ; Author ........: AspirinJunkie ; ================================================================================================= Func __cb_NormalComparison(ByRef Const $a, ByRef Const $b) Return $a > $b ? 1 : $a = $b ? 0 : -1 EndFunc ;==>__cb_NormalComparison1 point -
You're right both, $iMaxlen length is too much. Instead, 10 could be enough. So now, the code is shorter : #include<array.au3> $sString = "B|A|A|C|C|AB|DDD|BAAS|003|100|02" $s = Execute("'" & StringRegExpReplace($sString, "([^|]+)", "' & StringFormat('%010i', StringLen('$1')) & '$1' & '") & "'") $res = StringRegExp($s, "[^|]+", 3) _ArraySort($res) For $i = 0 To UBound($res) - 1 $res[$i] = StringTrimLeft($res[$i], 10) Next _ArrayDisplay($res)1 point
-
Hi, For those of you still using monochrome monitors, or who have some degree of colour-blindness, I would like to announce that we have a new forum Moderator - JLogan3o13. He has kindly agreed to join the Mod team and I would like to take this opportunity to welcome him - I am sure you will all join with me in wishing him well , because he will certainly need it! M231 point
-
First post on the forums Thanks so much for this! Made my day a lot easier! I'm using the HttpGet function in a GUI and if the page is not available my GUI starts freezing up so I added in $oHTTP.SetTimeouts to help with error handling. Func HttpGet($sURL, $sData = "") Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") $oHTTP.Open("GET", $sURL & "?" & $sData, False) $oHTTP.SetTimeouts(50, 50, 50, 50) If (@error) Then Return SetError(1, 0, 0) $oHTTP.Send() If (@error) Then Return SetError(2, 0, 0) If ($oHTTP.Status <> 200) Then Return SetError(3, 0, 0) Return SetError(0, 0, $oHTTP.ResponseText) EndFunc ;==>HttpGet The values are for ResolveTimeout, ConnectTimeout, SendTimeout, ReceiveTimeout. I've set to 50ms because I'm working with a LAN connection and my requests are tiny.1 point