Jump to content

Recommended Posts

Im trying to iterate through a 2d array created by 

ProcessList()

function that returns a 2d array containing names and pid's, i wanted to filter through the names and delete entries that have "svchost.exe" and this is how i did it

Func _Sanitize($array)
    For $x = 1 To UBound($array) - 1
          ConsoleWrite($array[$x][0] & @CRLF)
        If $array[$x][0] == "svchost.exe" Then
            _ArrayDelete($array, $x)
        EndIf
    Next
EndFunc   ;==>_Sanitize

And i get this error message

Quote

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
If $array[$x][0] == "svchost.exe" Then

If ^ ERROR

What is wrong?

Share this post


Link to post
Share on other sites

If you're going to delete elements of an array in a loop, you have to run the loop in reverse. Instead of

For $x = 1 To UBound($array) - 1

Use this

For $x = UBound($array) - 1  To 1 Step - 1

 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Oh it makes sense, i get it now because i am deleting entries my array is getting smaller and the for loop will fail because it wont have those entries at the bottom anymore. Thanks for the help.

Share this post


Link to post
Share on other sites
Posted (edited)

What @Subz and @BrewManNH said, and change this

If $array[$x][0] == "svchost.exe" Then ; AutoIT uses only single "=" for "equals"

;change it to this
If $array[$x][0] = "svchost.exe" Then

 

 

Edited by Dionysis

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By nooneclose
      Hello everyone, I am wondering if and how it is possible to connect my AutoIt script to a different email in my outlook. I have two different accounts when I open outlook. The first which my script always connects to is my own email while the second is a group email account. How or can I make the script connect to the second one and access its inbox instead of mine? This is all work related so no funny business here. 
      Global $oOutlook = _OL_Open() ; Store all the Unread emails into an array Global $aItems = _OL_ItemFind($oOutlook, "*\Outlook-UDF-Test", $olMail, _ "[UnRead]=True", "Subject", "Maintenance Request from Eagle's Nest", "EntryID,Subject", "", 1) ; Display the array of unRead emails If IsArray($aItems) Then ;_ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind - Unread mails") Else MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", _ "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended) EndIf ; Get the number of unread emails Global $numberOfUnRead = UBound($aItems, $UBOUND_ROWS) - 1 ;MsgBox("", "Number of Unread emails", $numberOfUnRead) ConsoleWrite("Number of unread emails: " & $numberOfUnRead & @CRLF) I might be missing some code in the post but my code works It's just so long I don't want to post all 2300+ lines. 
      Thank you for the help I greatly appreciate this community. 
    • By TheDcoder
      Hello everyone, it has been a while since I have been involved in a serious AutoIt-related project discussion in the forums here, so it feels good to be back at it
      First a little backstory, a few months back (or a year ago) I made the switch to Linux from Windows... there were several reasons as to why I was motivated to do it, but the main things was Windows 10 was getting out of hand, it didn't offer enough freedom out of the box (restrictive settings, greedy defaults etc.) and had several issues with all kinds of software, many of them mysteriously hard to fix.
      I did have Linux installed as my secondary operating system for few years at that point and I began to see me regularly use it more than Windows, so one day I went ahead and said "fork it", I have stuck to Linux from that point on as my primary operating system.
      Windows is still installed in my computer and I also have a virtual machine with the latest version of Windows 10 on it, primarily because I still use Windows to write software using AutoIt as part of my job (freelance).
      I was pretty sad about the fact that I could no longer use AutoIt to make stuff for myself (since it doesn't run on Linux), I missed sharing code with the community here, this was a great hobby for me as AutoIt is what got me start with programming (even though I had tried several times to get into other languages before, those attempts were never as successful as what I have done in AutoIt).
      In Linux there is no language which is similar to AutoIt unfortunately, there are a few things which come close but are not on par with AutoIt's ease of use. As some of you may know, I have recently started working on other projects using the C language, it is a great step I have taken and I am learning a lot... but it is still not easy to create quick scripts or programs in C, due to the amount of configuration and dedication it takes to make a C program, also it is not ideal for sharing as multiple source files are involved. And on top of that you still have to deal with platform-specific APIs since C is a low-level language.
      (Getting back to core of this topic's subject)
      To solve this issue and to sharpen my programming skills, I could start working on an alternate cross-platform implementation of the AutoIt language which should be backwards compatible with the current AutoIt v3 on C
      The primary aim in the beginning is to implement all the basic functions (File, String, Numbers etc.)  in AutoIt so that it is possible to make basic and fundamental scripts which would work in both Windows and Linux
      The main features would be:
      Cross-platform (Linux and Windows with the possibility supporting of Mac) Backward compatible with AutoIt 3 Byte-code based interpreter instead of source interpreter Easy to use (just like the current AutoIt) The advantage of having a byte-code based interpreter is that it makes the interpreter lighter and faster since it doesn't have to deal with parsing the source code, this would also open the door for some compile time optimizations... another bonus thing for those who don't like their source code present inside the compiler binaries is that it should be impossible to get hands on the original source code, this of course does not mean that decompilation can be stopped... it merely means that anyone decompiling would have to reconstruct the code from the byte-code.
       
      We can later on implement GUI related functions and maybe even automation related functions if the project gets enough traction
      I am adding a poll to keep track of people who are willing to invest in this project or would like to see it come into existence. Welcome any comments, suggestions etc.
      Obviously I will have a lot to learn and my work might interfere with this at times, but with enough interest I can see myself working on this to deliver a very basic prototype which could be used with basic scripts.
       
    • By FordsFinest
      I have a macro that works well on 95% of computers. However, I am running into an issue on a couple computers where the _GUICtrlTreeView_ClickItem clicks the wrong item (an item or two below the correct one). Both the ExpandItem and SelectItem command work fine, just the click item is off on these computers (and only their user names). I'm not sure if some temp file somewhere is causing an issue or what. Note, using ONLY selectitem results in inconsistent focusing (item appears focused but the next command won't always work correctly). Hence my need to use the clickitem command.
      Any help would be appreciated.
      _GUICtrlTreeView_Expand($hWnd, $Array2[$i]) ;Expand $model Sleep(250) _GUICtrlTreeView_SelectItem($hWnd, $Array2[$i]) ;Select $model Sleep(150) _GUICtrlTreeView_ClickItem($hWnd, $Array2[$i]) ;Click $model Sleep(150) EndIf  
    • By nacerbaaziz
      hello all, and welcome to this tool
      the NB-Password_generator is a small tool which allow you to create a strong passwords
      with this tool you can create a random passwords using :
      1. capital letters
      2. small letters
      3. numbers
      4. symbols
      be sure that you can check any option that  you want and uncheck what you don't want to use
      this tool allow you to create a password from 6 letters to 150 lettersNB-Password_generator.zip
      at the end please accept my greetings
      am waiting for your commants
    • By Malkey
      _ArrayMultiSort - This function sorts many columns (with optional case sensitivity, ascending or descending, and in any specific order) of an array.

      The following three functions _ArraySort,  __ArrayQuickSort1D,  and __ArrayQuickSort2D from the Array.au3 include file had to be modified to allow case sensitive sorting.
      The modified functions are renamed by appending a "C" for "Case" to each function's name giving _ArraySortC, __ArrayQuickSort1DC, and __ArrayQuickSort2DC. 
      The modifications involve each of these functions having a trailing parameter, $iCase, added, and, within these functions wherever the function "StringCompare" occurs, its third parameter, $iCase, is inserted. So when $iCase = 0, StringCompare is not case sensitive.  When $iCase = 1, StringCompare is case sensitive.
      Here is the UDF containing the functions used to sort arrays with case sensitivity.
      ArrayMultiSortCase.au3
      #include-once ; https://www.autoitscript.com/forum/topic/198148-_arraymultisort-sort-multiple-columns-with-case-sensitivity/ ; File Name: #include <ArrayMultiSortCase.au3> ;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ; #INCLUDES# ========================================================================================================= #include <Array.au3> ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _ArrayMultiSort ; Description ...: Sort a 1D or, sort a 2D array with the ability to specify which columns to sort and which direction to sort for each column. ; Syntax.........: _ArrayMultiSort(ByRef $avArray[, $sSort = '0a'[, $iStartRow = 0[, $iEndRow = 0]]]) ; Parameters ....: $avArray - Array to sort ; $sSort - [optional] The default setting only sorts the first column, column 0, in ascending order. Otherwise, $sSort is ; a string made up of comma separated column descriptors which contains a column number, sort direction and case ; sensitivity for that column. These 3 fields can be in any order in the column descriptor. Each column ; descriptor shows the sort order of columns of the array from left to right. ; "a" - Ascending order 0-9,A-Z,a-z (Without "a" or "d" default is "a") ; "d" - Descending order z-a,Z-A,9-0 ; "c" - sort that column with case sensitivity. ; No "c" present, that column is sorted with case insensitivity (default). ; Within the column descriptors, spaces are optional; and, ; Upper or lower case column descriptors, "CAD" or "cad", are recognized as the same - use either. ; Examples of the $sSort variable:- ; "3 ac, CD2, 0C, d1" -> First sort col#3 (case sensitive, ascending). ; Secondly sort col#2 (case sensitive, descending). ; Thirdly sort col#0 (case sensitive, ascending[default]). ; Lastly sort col#1 (case insensitive[default], descending). ; "0" or "" -> Sort col#0 (case insensitive[default], ascending[default]). ; See https://www.autoitscript.com/forum/topic/198148-_arraysort-_arraymultisort-with-case-sensitivity/?do=findComment&comment=1422656 ; $iStartRow - [optional] Row index of array to start sorting at. ; $iEndRow - [optional] Row index of array to stop sorting at. ; Return values .: Success - 1 ; Failure - 0, @error set to the same as returned from _ArraySort() function. (See _ArraySort in AutoIt help file) ; Author ........: Malkey ; Modified.......: ; Remarks .......: Updated version from https://www.autoitscript.com/forum/topic/166426-_filelisttoarray-sorting/?do=findComment&comment=1216234 ; This function requires the __TestExp function, and #Include <Array.au3> and the case sensitive versions of _ArraySort, ; __ArrayQuickSort1D, and __ArrayQuickSort2D. ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _ArrayMultiSort(ByRef $aArray, $sSort = '0a', $iStartRow = 0, $iEndRow = 0) Local $iCol1, $Dir, $iLastRow, $iStart, $iRetV, $iEnd, $Err, $aSort2D[0][3] ;------------ $sSort (string) to $aSort2D (array) ----------- _ArrayAdd($aSort2D, Execute(StringTrimRight(StringRegExpReplace(StringStripWS($sSort, 8), "(?i)(c)(\d+)([ad]),?|([ad])(\d+)(c),?" & _ ; RE pattern 2 possibilities (BackRef 1 to 6) "|(\d+)([ad])(c),?|(\d+)(c)([ad]),?|([ad])(c)(\d+),?|(c)([ad])(\d+),?|([ad])(\d+),?|(c)(\d+),?|(\d+)(c),?|(\d+)([ad]),?|(\d+),?", _ ; RE pattern 9 possibilities (BackRef 7 to 27) "('$1$6$9${11}${14}${16}${21}${24}'='c')*1&""|$2$5$7${10}${15}${18}${20}${22}${23}${25}${27}|""&('$3$4$8${12}${13}${17}${19}${26}'='d')*1&@CRLF&"), _ ; The 'replace' parameter of StringRegExpReplace() 7))) ; End of StringTrimRight() that removes trailing "&@CRLF&" ;_ArrayDisplay($aSort2D, "", "", 0, Default, "Case|Col#|Asc/Desc") ; ------------------------------------------------------------ If $iEndRow = 0 Or ($iEndRow > (UBound($aArray) - 1)) Then $iLastRow = UBound($aArray) - 1 $iStart = -1 $iEnd = -1 ; Sort the first column to be sorted. $iRetV = _ArraySortC($aArray, Number($aSort2D[0][2]), $iStartRow, $iLastRow, Number($aSort2D[0][1]), 0, Number($aSort2D[0][0])) ; Sort on the first column (stored in $aSort2D[0][1]) $Err = @error If $iRetV = 0 Then Return SetError($Err, 0, 0) ; Sort all remaining columns. For $j = 1 To UBound($aSort2D) - 1 ; For each group of equal values in the previous sorted column, sort the present column values on the same rows of each group. $iStart = -1 For $i = $iStartRow To $iLastRow Switch $i Case $iStartRow If $i <> $iLastRow Then If __TestExp($aArray, $aSort2D, $i, $j) Then $iStart = $i + 1 $iEnd = $i + 1 Else $iStart = $i $iEnd = $i + 1 EndIf EndIf Case $iLastRow $iEnd = $iLastRow If $iStart <> $iEnd Then $iRetV = _ArraySortC($aArray, Number($aSort2D[$j][2]), $iStart, $iEnd, Number($aSort2D[$j][1]), 0, Number($aSort2D[$j][0])) $Err = @error EndIf Case Else If __TestExp($aArray, $aSort2D, $i, $j) Then $iEnd = $i If $iStart <> $iEnd Then $iRetV = _ArraySortC($aArray, Number($aSort2D[$j][2]), $iStart, $iEnd, Number($aSort2D[$j][1]), 0, Number($aSort2D[$j][0])) $Err = @error EndIf $iStart = $i + 1 $iEnd = $iStart Else $iEnd = $i EndIf EndSwitch Next Next Return SetError($Err, 0, $iRetV) EndFunc ;==>_ArrayMultiSort ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __TestExp ; Description ...: Creates and tests a test expression. Internally used function by the _ArrayMultiSort() function ; Syntax.........: __TestExp($aA, $aC, $k, $m) ; Parameters ....: $aA - The 2D array to be sorted. ; $aC - A 2D array containing to column sorting order and each column's direction of sorting.(See Modified note) ; $k - The array's row index of the data being sorted. ; $m - The array's row index of the current column being sorted ; Return values .: 1 - When any of the created test expressions are true; or, ; 0 - When all of the created test expressions are false. ; Author ........: Malkey ; Modified.......: Malkey 2019/3/9 Array $aC is now [n][3] where [n][0] is case sensitivity; [n][1] is Column#; [n][2] is sort asc or desc. ; Remarks .......: This function is used internally by the _ArrayMultiSort function. The created expression tests the particular ; row, $k, of the test data, for each previously sorted column, $m -1, wheather the value in that column, $aA[$k][$aC[$w][1]], ; is not equal to the next value in that same column, $aA[$k + 1][$aC[$w][1]], where $aC[$w][1] contains the previously sorted column number. ; =============================================================================================================================== Func __TestExp(ByRef $aA, ByRef $aC, $k, $m) For $w = 0 To $m - 1 If ($aA[$k + 1][$aC[$w][1]]) <> ($aA[$k][$aC[$w][1]]) Then ; Like an "Or" join statements. If just one of the expressions in the For-Next loop is true, then function returns "1" (True). Return 1 EndIf Next Return 0 EndFunc ;==>__TestExp ; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ; =============================================================================================== ; The following three function, ; _ArraySortC, __ArrayQuickSort1DC, and __ArrayQuickSort2DC are modied copies of the functions, ; _ArraySort, __ArrayQuickSort1D, and __ArrayQuickSort2D from the Array.au3 include file. ; The modifications allow case sensitive sorting of arrays. ; =============================================================================================== ; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ; #FUNCTION# ==================================================================================================================== ; Author ........: Jos ; Modified.......: LazyCoder - added $iSubItem option; Tylo - implemented stable QuickSort algo; Jos - changed logic to correctly Sort arrays with mixed Values and Strings; Melba23 - implemented stable pivot algo; Malkey - added case sensitive sorting. ; =============================================================================================================================== Func _ArraySortC(ByRef $aArray, $iDescending = 0, $iStart = 0, $iEnd = 0, $iSubItem = 0, $iPivot = 0, $iCase = 0) If $iDescending = Default Then $iDescending = 0 If $iStart = Default Then $iStart = 0 If $iEnd = Default Then $iEnd = 0 If $iSubItem = Default Then $iSubItem = 0 If $iPivot = Default Then $iPivot = 0 If $iCase = Default Then $iCase = 0 If Not IsArray($aArray) Then Return SetError(1, 0, 0) Local $iUBound = UBound($aArray) - 1 If $iUBound = -1 Then Return SetError(5, 0, 0) ; Bounds checking If $iEnd = Default Then $iEnd = 0 If $iEnd < 1 Or $iEnd > $iUBound Or $iEnd = Default Then $iEnd = $iUBound If $iStart < 0 Or $iStart = Default Then $iStart = 0 If $iStart > $iEnd Then Return SetError(2, 0, 0) ; Sort Switch UBound($aArray, $UBOUND_DIMENSIONS) Case 1 If $iPivot Then ; Switch algorithms as required __ArrayDualPivotSort($aArray, $iStart, $iEnd) Else __ArrayQuickSort1DC($aArray, $iStart, $iEnd, $iCase) EndIf If $iDescending Then _ArrayReverse($aArray, $iStart, $iEnd) Case 2 If $iPivot Then Return SetError(6, 0, 0) ; Error if 2D array and $iPivot Local $iSubMax = UBound($aArray, 2) - 1 ; $UBOUND_COLUMNS (2) If $iSubItem > $iSubMax Then Return SetError(3, 0, 0) If $iDescending Then $iDescending = -1 Else $iDescending = 1 EndIf __ArrayQuickSort2DC($aArray, $iDescending, $iStart, $iEnd, $iSubItem, $iSubMax, $iCase) Case Else Return SetError(4, 0, 0) EndSwitch Return 1 EndFunc ;==>_ArraySortC ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __ArrayQuickSort1DC (Appended 'C' for case sensitivity) ; Description ...: Helper function for sorting 1D arrays ; Syntax.........: __ArrayQuickSort1D ( ByRef $aArray, ByRef $iStart, ByRef $iEnd ) ; Parameters ....: $aArray - Array to sort ; $iStart - Index of array to start sorting at ; $iEnd - Index of array to stop sorting at ; Return values .: None ; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima ; Modified.......: Malkey ; Remarks .......: For Internal Use Only. All StringCompare functions have $iCase parameter added for optional case sensitivity. ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func __ArrayQuickSort1DC(ByRef $aArray, Const ByRef $iStart, Const ByRef $iEnd, Const ByRef $iCase) If $iEnd <= $iStart Then Return Local $vTmp ; InsertionSort (faster for smaller segments) If ($iEnd - $iStart) < 15 Then Local $vCur For $i = $iStart + 1 To $iEnd $vTmp = $aArray[$i] If IsNumber($vTmp) Then For $j = $i - 1 To $iStart Step -1 $vCur = $aArray[$j] ; If $vTmp >= $vCur Then ExitLoop If ($vTmp >= $vCur And IsNumber($vCur)) Or (Not IsNumber($vCur) And StringCompare($vTmp, $vCur, $iCase) >= 0) Then ExitLoop $aArray[$j + 1] = $vCur Next Else For $j = $i - 1 To $iStart Step -1 If (StringCompare($vTmp, $aArray[$j], $iCase) >= 0) Then ExitLoop $aArray[$j + 1] = $aArray[$j] Next EndIf $aArray[$j + 1] = $vTmp Next Return EndIf ; QuickSort Local $L = $iStart, $R = $iEnd, $vPivot = $aArray[Int(($iStart + $iEnd) / 2)], $bNum = IsNumber($vPivot) Do If $bNum Then ; While $aArray[$L] < $vPivot While ($aArray[$L] < $vPivot And IsNumber($aArray[$L])) Or (Not IsNumber($aArray[$L]) And StringCompare($aArray[$L], $vPivot, $iCase) < 0) $L += 1 WEnd ; While $aArray[$R] > $vPivot While ($aArray[$R] > $vPivot And IsNumber($aArray[$R])) Or (Not IsNumber($aArray[$R]) And StringCompare($aArray[$R], $vPivot, $iCase) > 0) $R -= 1 WEnd Else While (StringCompare($aArray[$L], $vPivot, $iCase) < 0) $L += 1 WEnd While (StringCompare($aArray[$R], $vPivot, $iCase) > 0) $R -= 1 WEnd EndIf ; Swap If $L <= $R Then $vTmp = $aArray[$L] $aArray[$L] = $aArray[$R] $aArray[$R] = $vTmp $L += 1 $R -= 1 EndIf Until $L > $R __ArrayQuickSort1DC($aArray, $iStart, $R, $iCase) __ArrayQuickSort1DC($aArray, $L, $iEnd, $iCase) EndFunc ;==>__ArrayQuickSort1DC ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __ArrayQuickSort2DC (Appended 'C' for case sensitivity) ; Description ...: Helper function for sorting 2D arrays ; Syntax.........: __ArrayQuickSort2D ( ByRef $aArray, ByRef $iStep, ByRef $iStart, ByRef $iEnd, ByRef $iSubItem, ByRef $iSubMax ) ; Parameters ....: $aArray - Array to sort ; $iStep - Step size (should be 1 to sort ascending, -1 to sort descending!) ; $iStart - Index of array to start sorting at ; $iEnd - Index of array to stop sorting at ; $iSubItem - Sub-index to sort on in 2D arrays ; $iSubMax - Maximum sub-index that array has ; Return values .: None ; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima ; Modified.......: Malkey ; Remarks .......: For Internal Use Only. All StringCompare functions have $iCase parameter added for optional case sensitivity. ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func __ArrayQuickSort2DC(ByRef $aArray, Const ByRef $iStep, Const ByRef $iStart, Const ByRef $iEnd, Const ByRef $iSubItem, Const ByRef $iSubMax, Const ByRef $iCase) If $iEnd <= $iStart Then Return ; QuickSort Local $vTmp, $L = $iStart, $R = $iEnd, $vPivot = $aArray[Int(($iStart + $iEnd) / 2)][$iSubItem], $bNum = IsNumber($vPivot) Do If $bNum Then ; While $aArray[$L][$iSubItem] < $vPivot While ($iStep * ($aArray[$L][$iSubItem] - $vPivot) < 0 And IsNumber($aArray[$L][$iSubItem])) Or (Not IsNumber($aArray[$L][$iSubItem]) And $iStep * StringCompare($aArray[$L][$iSubItem], $vPivot, $iCase) < 0) $L += 1 WEnd ; While $aArray[$R][$iSubItem] > $vPivot While ($iStep * ($aArray[$R][$iSubItem] - $vPivot) > 0 And IsNumber($aArray[$R][$iSubItem])) Or (Not IsNumber($aArray[$R][$iSubItem]) And $iStep * StringCompare($aArray[$R][$iSubItem], $vPivot, $iCase) > 0) $R -= 1 WEnd Else While ($iStep * StringCompare($aArray[$L][$iSubItem], $vPivot, $iCase) < 0) $L += 1 WEnd While ($iStep * StringCompare($aArray[$R][$iSubItem], $vPivot, $iCase) > 0) $R -= 1 WEnd EndIf ; Swap If $L <= $R Then For $i = 0 To $iSubMax $vTmp = $aArray[$L][$i] $aArray[$L][$i] = $aArray[$R][$i] $aArray[$R][$i] = $vTmp Next $L += 1 $R -= 1 EndIf Until $L > $R __ArrayQuickSort2DC($aArray, $iStep, $iStart, $R, $iSubItem, $iSubMax, $iCase) __ArrayQuickSort2DC($aArray, $iStep, $L, $iEnd, $iSubItem, $iSubMax, $iCase) EndFunc ;==>__ArrayQuickSort2DC Here is an example using the _ArrayMultiSort function.
      #include <ArrayMultiSortCase.au3> ;#cs ; --------------- Create test data -------------- Global $array[2001][5] = [["Col 0", "Col 1", "Col 2", "Col 3", "Col 4"]] ; For $i = 1 To 2000 $array[$i][0] = (Random(0, 1, 1) ? Chr(Random(97, 99, 1)) : Chr(Random(65, 67, 1))) $array[$i][1] = (Random(0, 1, 1) ? Chr(Random(97, 99, 1)) : Chr(Random(65, 67, 1))) $array[$i][2] = (Random(0, 1, 1) ? Int(Random(0, 2, 1) & Random(1, 3, 1)) : (Random(0, 1, 1) ? Chr(Random(97, 99, 1)) : Chr(Random(65, 67, 1)))) $array[$i][3] = Random(1, 5, 1) $array[$i][4] = Random(1, 5, 1) Next ; -----------> End of Create test data ----------- Local $aArray = $array ; Sort column 0(asc+case sensitive) then column 1(desc+case insensitive), then columns 2(asc+case sensitive), 3(desc+case insensitive), and 4(asc+case insensitive). _ArrayMultiSort($aArray, "c0a,1d,c2a,3d,4a", 1) _ArrayDisplay($aArray, "Sorted c0a,1d,c2a,3d,4a") Local $aArray = $array _ArrayMultiSort($aArray, "1d, c0, c2d, 3, 4d", 1) ; Sort column 1(desc) then column 0(asc+case sensitive), then columns 2(desc+case sensitive), 3(asc), and 4(desc). _ArrayDisplay($aArray, "Sorted 1d,c0a,c2d,3a,4d") ;#ce ;#cs Local $a_Test[18][2] = [["Color", "#"], ["Black", 3], ["Blue", 3], ["white", 3], ["Brown", 4], ["Clear", 3], ["Gold", 3], ["gold", 3], _ ["green", 3], ["Green", 3], ["brown", 4], ["Purple", 3], ["Red", 3], ["Royal", 3], ["Silver", 2], ["Sky", 2], ["White", 3], ["Yellow", 5]] _ArrayDisplay($a_Test, "Unsorted") _ArrayMultiSort($a_Test, "1d,0a", 1) ; Sort Column 1 descending, then Column 0 ascending _ArrayDisplay($a_Test, "Sorted 1d,0a Starting @ row1") _ArrayMultiSort($a_Test, "1d,c0a", 1) ; Sort Column 1 descending, then Column 0 ascending+case sensitive _ArrayDisplay($a_Test, "Sorted 1d,c0a Starting @ row1") ;#ce ;#cs Local $aTest[] = [2, "Black", "Blue", 3, "Brown", 4, "Clear", 3, "Gold", 3, "green", 13, "Gray", 3, "gold", 23, "Green", 3, "gray", 33, "Purple", 3, "Red", 3, "Royal", 3, "Silver", 2, "Sky", 2, "White", 3, "Yellow", 5] _ArrayMultiSort($aTest, 'c0a') _ArrayDisplay($aTest, "Sorted c0a") ;#ce  
      Here is an example to test the _ArraySortC function which is the same as _ArraySort function, but with an extra parameter "$iCase" added.
      #include <ArrayMultiSortCase.au3> Local $array[9][3] = [ _ ["age", 40, 8], _ [1, 32, 7], _ [4, 16, 9], _ ["ace", 32, 7], _ ["ass", 16, 9], _ [35, 32, 7], _ [24, 16, 9], _ ["Ama", 5, 0], _ ["Aft", 19, 6]] Local $avArray = $array ;_ArrayDisplay($avArray, "$avArray BEFORE _ArraySort()") _ArraySortC($avArray) ;, 0, 0, 0, 0, 0) _ArrayDisplay($avArray, "Asc col0") $avArray = $array _ArraySortC($avArray, 0, 0, 0, 0, 0, 1) _ArrayDisplay($avArray, "Asc col0; case-sensitive") $avArray = $array _ArraySortC($avArray, 1, 0, 0, 0, 0, 1) _ArrayDisplay($avArray, "Desc col0; case-sensitive") $avArray = $array _ArraySortC($avArray, 1, 1, 0, 0, 0, 1) _ArrayDisplay($avArray, "Start row1; Desc col0; case-sensitive")  
×
×
  • Create New...