Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/08/2022 in all areas

  1. This should match any PC Name (regardless of capitalization) as long as the line structure follows your example. #include <Array.au3> Local $sText = "[libndi_newtek @ 000001f53af6af40] Found 3 NDI sources:" & @CRLF & _ "[libndi_newtek @ 000001f53af6af40] 'PC-NAME (Remote Connection 1)' 'ndi-app:PC-NAME%20(Remote%20Connection%201)'" & @CRLF & _ "[libndi_newtek @ 000001f53af6af40] 'PC-NAME (NDI - Output 1)' '192.168.1.201:5961'" & @CRLF & _ "[libndi_newtek @ 000001f53af6af40] 'ANOTHER-PC (NDI - Output 3)' '192.168.1.201:5962'" & @CRLF & _ "[libndi_newtek @ 000001f53af6af40] 'PC-Name2 (NDI - Output 3)' '192.168.1.201:5962'" & @CRLF & _ "[libndi_newtek @ 000001f53af6af40] 'Whatever PC-Name (NDI - Output 3)' '192.168.1.201:5962'" & @CRLF & _ "[libndi_newtek @ 000001f53af6af40] 'unknown' '192.168.1.201:5962'" & @CRLF & _ "dummy: Immediate exit requested" Local $aArray = StringRegExp($sText,"\].*?'(.+?)'", 3) _ArrayDisplay($aArray)
    2 points
  2. Ok... here is the current issue I have with properly identifying whether it is a Script defined Variable or a Standard used Variable: Local $FO_OVERWRITE ; is local definition Local $FO_ANSI = 1 + 1, $FO_OVERWRITE ; is local definition Local $hOut = 25 + $FO_OVERWRITE ; Standard Global Variable Local $hOut = FileOpen("temp.au3", $FO_OVERWRITE) ; Standard Global Variable I have been playing with regex tests but have failed till now to properly identify the third line correctly being a usage of the global variable. So I am leaning toward not making it more complex and let au3check do its job by telling you you have a duplicate Variable defined.
    1 point
  3. Maybe this : #include <Array.au3> Local $sText = "[libndi_newtek @ 000001f53af6af40] Found 3 NDI sources:" & @CRLF & _ "[libndi_newtek @ 000001f53af6af40] 'PC-NAME (Remote Connection 1)' 'ndi-app:PC-NAME%20(Remote%20Connection%201)'" & @CRLF & _ "[libndi_newtek @ 000001f53af6af40] 'PC-NAME (NDI - Output 1)' '192.168.1.201:5961'" & @CRLF & _ "[libndi_newtek @ 000001f53af6af40] 'ANOTHER-PC (NDI - Output 3)' '192.168.1.201:5962'" & @CRLF & _ "dummy: Immediate exit requested" Local $aArray = StringRegExp($sText,"'(PC-NAME.+?|ANOTHER-PC.+?)'", 3) _ArrayDisplay($aArray)
    1 point
  4. [New Release] - 06 April 2019 Added: Error-checking for sensible column numbers in the $aSortData array, with an additional error status. ------------------------------------------------------------------------------------------------------------------------ While answering a recent question about sorting a ListView on several columns, I developed this function to sort a 2D array on several columns and I though I might give it a wider audience. Here is the function: #include-once ;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ; #INCLUDES# ========================================================================================================= #include <Array.au3> ; =============================================================================================================================== ; #INDEX# ======================================================================================================================= ; Title .........: ArrayMultiColSort ; AutoIt Version : v3.3.8.1 or higher ; Language ......: English ; Description ...: Sorts 2D arrays on several columns ; Note ..........: ; Author(s) .....: Melba23 ; Remarks .......: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _ArrayMultiColSort : Sort 2D arrays on several columns ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#================================================================================================= ; __AMCS_SortChunk : Sorts array section ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _ArrayMultiColSort ; Description ...: Sort 2D arrays on several columns ; Syntax.........: _ArrayMultiColSort(ByRef $aArray, $aSortData[, $iStart = 0[, $iEnd = 0]]) ; Parameters ....: $aArray - The 2D array to be sorted ; $aSortData - 2D array holding details of the sort format ; Format: [Column to be sorted, Sort order] ; Sort order can be either numeric (0/1 = ascending/descending) or a ordered string of items ; Any elements not matched in string are left unsorted after all sorted elements ; $iStart - Element of array at which sort starts (default = 0) ; $iEnd - Element of array at which sort endd (default = 0 - converted to end of array) ; Requirement(s).: v3.3.8.1 or higher ; Return values .: Success: No error ; Failure: @error set as follows ; @error = 1 with @extended set as follows (all refer to $sIn_Date): ; 1 = Array to be sorted not 2D ; 2 = Sort data array not 2D ; 3 = More data rows in $aSortData than columns in $aArray ; 4 = Start beyond end of array ; 5 = Start beyond End ; @error = 2 with @extended set as follows: ; 1 = Invalid string parameter in $aSortData ; 2 = Invalid sort direction parameter in $aSortData ; 3 = Invalid column index in $aSortData ; Author ........: Melba23 ; Remarks .......: Columns can be sorted in any order ; Example .......; Yes ; =============================================================================================================================== Func _ArrayMultiColSort(ByRef $aArray, $aSortData, $iStart = 0, $iEnd = 0) ; Errorchecking ; 2D array to be sorted If UBound($aArray, 2) = 0 Then Return SetError(1, 1, "") EndIf ; 2D sort data If UBound($aSortData, 2) <> 2 Then Return SetError(1, 2, "") EndIf If UBound($aSortData) > UBound($aArray) Then Return SetError(1, 3) EndIf For $i = 0 To UBound($aSortData) - 1 If $aSortData[$i][0] < 0 Or $aSortData[$i][0] > UBound($aArray, 2) -1 Then Return SetError(2, 3, "") EndIf Next ; Start element If $iStart < 0 Then $iStart = 0 EndIf If $iStart >= UBound($aArray) - 1 Then Return SetError(1, 4, "") EndIf ; End element If $iEnd <= 0 Or $iEnd >= UBound($aArray) - 1 Then $iEnd = UBound($aArray) - 1 EndIf ; Sanity check If $iEnd <= $iStart Then Return SetError(1, 5, "") EndIf Local $iCurrCol, $iChunk_Start, $iMatchCol ; Sort first column __AMCS_SortChunk($aArray, $aSortData, 0, $aSortData[0][0], $iStart, $iEnd) If @error Then Return SetError(2, @extended, "") EndIf ; Now sort within other columns For $iSortData_Row = 1 To UBound($aSortData) - 1 ; Determine column to sort $iCurrCol = $aSortData[$iSortData_Row][0] ; Create arrays to hold data from previous columns Local $aBaseValue[$iSortData_Row] ; Set base values For $i = 0 To $iSortData_Row - 1 $aBaseValue[$i] = $aArray[$iStart][$aSortData[$i][0]] Next ; Set start of this chunk $iChunk_Start = $iStart ; Now work down through array For $iRow = $iStart + 1 To $iEnd ; Match each column For $k = 0 To $iSortData_Row - 1 $iMatchCol = $aSortData[$k][0] ; See if value in each has changed If $aArray[$iRow][$iMatchCol] <> $aBaseValue[$k] Then ; If so and row has advanced If $iChunk_Start < $iRow - 1 Then ; Sort this chunk __AMCS_SortChunk($aArray, $aSortData, $iSortData_Row, $iCurrCol, $iChunk_Start, $iRow - 1) If @error Then Return SetError(2, @extended, "") EndIf EndIf ; Set new base value $aBaseValue[$k] = $aArray[$iRow][$iMatchCol] ; Set new chunk start $iChunk_Start = $iRow EndIf Next Next ; Sort final section If $iChunk_Start < $iRow - 1 Then __AMCS_SortChunk($aArray, $aSortData, $iSortData_Row, $iCurrCol, $iChunk_Start, $iRow - 1) If @error Then Return SetError(2, @extended, "") EndIf EndIf Next EndFunc ;==>_ArrayMultiColSort ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __AMCS_SortChunk ; Description ...: Sorts array section ; Author ........: Melba23 ; Remarks .......: ; =============================================================================================================================== Func __AMCS_SortChunk(ByRef $aArray, $aSortData, $iRow, $iColumn, $iChunkStart, $iChunkEnd) Local $aSortOrder ; Set default sort direction Local $iSortDirn = 1 ; Need to prefix elements? If IsString($aSortData[$iRow][1]) Then ; Split elements $aSortOrder = StringSplit($aSortData[$iRow][1], ",") If @error Then Return SetError(1, 1, "") EndIf ; Add prefix to each element For $i = $iChunkStart To $iChunkEnd For $j = 1 To $aSortOrder[0] If $aArray[$i][$iColumn] = $aSortOrder[$j] Then $aArray[$i][$iColumn] = StringFormat("%02i-", $j) & $aArray[$i][$iColumn] ExitLoop EndIf Next ; Deal with anything that does not match If $j > $aSortOrder[0] Then $aArray[$i][$iColumn] = StringFormat("%02i-", $j) & $aArray[$i][$iColumn] EndIf Next Else Switch $aSortData[$iRow][1] Case 0, 1 ; Set required sort direction if no list If $aSortData[$iRow][1] Then $iSortDirn = -1 Else $iSortDirn = 1 EndIf Case Else Return SetError(1, 2, "") EndSwitch EndIf ; Sort the chunk Local $iSubMax = UBound($aArray, 2) - 1 __ArrayQuickSort2D($aArray, $iSortDirn, $iChunkStart, $iChunkEnd, $iColumn, $iSubMax) ; Remove any prefixes If IsString($aSortData[$iRow][1]) Then For $i = $iChunkStart To $iChunkEnd $aArray[$i][$iColumn] = StringTrimLeft($aArray[$i][$iColumn], 3) Next EndIf EndFunc ;==>__AMCS_SortChunk And here is an example to show it working: #include "ArrayMultiColSort.au3" #include <String.au3> ; Only used to fill array ; Create and display array Global $aArray[100][4] For $i = 0 To 99 $aArray[$i][0] = _StringRepeat(Chr(Random(65, 68, 1)), 5) $aArray[$i][1] = _StringRepeat(Chr(Random(74, 77, 1)), 5) $aArray[$i][2] = _StringRepeat(Chr(Random(80, 83, 1)), 5) $aArray[$i][3] = _StringRepeat(Chr(Random(87, 90, 1)), 5) Next _ArrayDisplay($aArray, "Unsorted") ; Copy arrays for separate examples below $aArray_1 = $aArray $aArray_2 = $aArray ; This sorts columns in ascending order - probably the most common requirement ; Sort requirement: ; Col 0 = Decending ; Col 1 = Ascending ; Col 2 = Required order of elements (note not alphabetic PQRS nor reverse SRQP) ; Col 3 = Ascending Global $aSortData[][] = [ _ [0, 1], _ [1, 0], _ [2, "SSSSS,QQQQQ,PPPPP,RRRRR"], _ [3, 0]] ; Sort and display array _ArrayMultiColSort($aArray_1, $aSortData) ; Display any errors encountered If @error Then ConsoleWrite("Oops: " & @error & " - " & @extended & @CRLF) _ArrayDisplay($aArray_1, "Sorted in order 0-1-2-3") ; But the UDF can sort columns in any order ; Sort requirement: ; Col 2 = Decending ; Col 0 = Ascending Global $aSortData[][] = [ _ [2, 1], _ [0, 0]] ; Sort and display array _ArrayMultiColSort($aArray_2, $aSortData) ; Display any errors encountered If @error Then ConsoleWrite("Oops: " & @error & " - " & @extended & @CRLF) _ArrayDisplay($aArray_2, "Sorted in order 2-0") And here are both in zip form: ArrayMultiColSort.zip As usual all comments welcome. M23
    1 point
×
×
  • Create New...