Jump to content

Function that takes array and finds unique indexes


Recommended Posts

Cannot get my head around this...I have an array of X, and in that array each index has 3 parts, I need to find the unique indexes of the main array

 

so main array would be

[0] ???|abc|down

[1] ???|abc|downorflapping

[2] ???|ccc|ccc

[3] ???|ddd|ddd

[4] ???|xyz|down

[5] ???|xyz|unresponsive

 

so that is the array that comes in, and I think I need to break that up in another array and then compare it to each other, but I am not able to get my head around it...the first element does not matter, but if the second element is found anywhere else in the main array, I need to take only one of them, I would like that to be a variable passed, that way I can call it more then once and get the unique values I am looking for...Anyone got an idea?

 

I have tried many different ways but cannot seem to get it right

$aListAlerts[6] = ["???|abc|down", "???|abc|downorflapping", "???|ccc|ccc", "???|ddd|ddd", "???|xyz|down", "???|xyz|unresponsive"]
 
 
 
 
_ArrayDisplay($aListAlerts, 'all alerts')

    Local $aNewArray[2]

    For $x = 0 To UBound($aListAlerts) - 1
        Local $aTestArray = StringSplit($aListAlerts[$x], '|', 2)
        If UBound($aTestArray) <= 1 Then ContinueLoop
        ConsoleWrite($x & '  X  ' & $aListAlerts[$x] & @CRLF)
        For $y = 0 To UBound($aListAlerts) - 1
            If $y = $x Then ContinueLoop
            If StringInStr($aListAlerts[$y], $aTestArray[1]) Then
                Local $aTestArray2 = StringSplit($aListAlerts[$y], '|', 2)
                ConsoleWrite($y & '  Y  ' & $aListAlerts[$y] & @CRLF)
                If UBound($aTestArray2) <= 1 Then ContinueLoop
                If $aTestArray2[2] <> $aTestArray[2] Then

                    If $aTestArray2[2] = 'Down' Then
                        If $aTestArray[2] = 'DownOrFlapping' Then
                            If _ArraySearch($aNewArray, $aListAlerts[$x]) <> @error Then
                            _ArrayAdd($aNewArray, $aListAlerts[$x])
                            ExitLoop
                            EndIf
                        EndIf
                    ElseIf $aTestArray2[2] = 'DownOrFlapping' Then
                        If $aTestArray[2] = 'Down' Then
                            If _ArraySearch($aNewArray, $aListAlerts[$x]) <> @error Then
                            _ArrayAdd($aNewArray, $aListAlerts[$x])
                            ExitLoop
                            EndIf
                        EndIf
                    Else
                        If _ArraySearch($aNewArray, $aListAlerts[$x]) = @error Then
                        _ArrayAdd($aNewArray, $aListAlerts[$x])
                        ExitLoop
                        EndIf
                    EndIf

                EndIf

            EndIf
        Next
    Next

    _ArrayDisplay($aNewArray)
 

 

edit does not look like tags are working?

edit - learned how to post code yea

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to post
Share on other sites

What about _ArrayUnique?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to post
Share on other sites

I do not think that will work, unless I read it wrong. I want to find the element with the letters that match and then find out if there is a matching one and only return one. As each of the elements in the main array are unique - it would just return my main array?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to post
Share on other sites

nitekran,

Try something like this (just displays hit results)

#include <array.au3>

local $aMain[6] = [ '???|abc|down', _
                    '???|abc|downorflapping', _
                    '???|ccc|ccc', _
                    '???|ddd|ddd', _
                    '???|xyz|down', _
                    '???|xyz|unresponsive' ]

; create and populate interim 2D array

local $aTmp[6][2]

for $1 = 0 to ubound($aMain) - 1

    $a10 = stringsplit($aMain[$1],'|')
    $aTmp[$1][0] = $a10[2]
    $aTmp[$1][1] = $a10[3]

Next

; compare each element to every other element - produce hit coordinates of elements

for $1 = 0 to ubound($aTmp,1) - 1
    for $2 = 0 to ubound($aTmp,2) - 1
        for $3 = 0 to ubound($aTmp,1) - 1
            for $4 = 0 to ubound($aTmp,2) - 1
                if $aTmp[$1][$2] = $aTmp[$3][$4] then
                    ConsoleWrite(stringformat('ele [%02i][%02i] = %-15s  matches ele [%02i][%02i] = %-15s',$1,$2,$aTmp[$1][$2],$3,$4,$aTmp[$3][$4]) & @LF)
                EndIf
            Next
        Next
    Next
Next

kylomas

edit: cleaned up / commented code

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to post
Share on other sites

Or using an extended array search UDF (doh! just worked on this and forgot about it!)

#include <array.au3>

local $aMain[6] = [ '???|abc|down', _
                    '???|abc|downorflapping', _
                    '???|ccc|ccc', _
                    '???|ddd|ddd', _
                    '???|xyz|down', _
                    '???|xyz|unresponsive' ]

; create and populate interim 2D array

local $aTmp[6][2]

for $1 = 0 to ubound($aMain) - 1

    $a10 = stringsplit($aMain[$1],'|')
    $aTmp[$1][0] = $a10[2]
    $aTmp[$1][1] = $a10[3]

Next

; compare each element to every other element - produce hit coordinates of elements

for $1 = 0 to ubound($aTmp,1) - 1
    for $2 = 0 to ubound($aTmp,2) - 1
        $a10 = _arrayfindallex($aTmp,$aTmp[$1][$2])
        ConsoleWrite($aTmp[$1][$2] & ' Found at ' & @lf)
        for $i = 0 to ubound($a10) - 1
            ConsoleWrite(@tab & $a10[$i][0] & @lf)
        Next
    next
Next



#region Functions
#include-once

; #INDEX# =======================================================================================================================
; Title .........: Array Functions Not in General Distribution
; AutoIt Version : 3.3.8.1
; Language ......: English
; Description ...: Collection of array functions that do not exist or can be enhanced (suffixed with "ex")
; ===============================================================================================================================

; #CURRENT# =====================================================================================================================
;_ArrayDeleteColumn_Function
;_ArrayFindAll_Function
; ===============================================================================================================================

; #FUNCTION# ====================================================================================================================
; Name...........: _ArrayDeleteColumn
; Description ...: Deletes Any Column of a 2 Dimensional Array
; Syntax.........: _ArrayDeleteColumn(Byref $avSourceArray,$Col = 1)
; Parameters ....: $avSourceArray   - [Byref] A 2 dimensional array of any number of columns.
;                  $iCol            - Integer number of the column that you want to delete.
; Return values .: Success          - @error is set to 0 and an array minus the column to delete is returned.
;                  Failure          - @error is set to one of the following:
;                                    1 - Parameter 1 is not a 2 dimensional array
;                                   |2 - Parameter 2 is not a number
;                                   |3 - Column to delete does not exist in the source array.
; Author ........: kylomas
; Modified.......: 05/03/2013
; Remarks .......: Version 1.0.0
; Example .......: Yes
; ===============================================================================================================================

Func _ArrayDeleteColumn(ByRef $avSourceArray, $iCol = 1)

    ; flush the parms

    If $iCol = -1 Or $iCol = Default Then $iCol = 1

    If UBound($avSourceArray, 0) <> 2 Then Return SetError(1)
    If Not IsNumber($iCol) And Not StringIsDigit($iCol) Then Return SetError(2)
    If $iCol > UBound($avSourceArray, 2) Or $iCol < 1 Then Return SetError(3)

    ; define receiving array with 2ND dimension - 1

    Local $aRet[UBound($avSourceArray, 1)][UBound($avSourceArray, 2) - 1]

    ; populate receiving array

    For $1 = 0 To UBound($aRet, 1) - 1
        For $2 = 0 To UBound($aRet, 2) - 1
            If $2 >= $iCol Then
                $aRet[$1][$2] = $avSourceArray[$1][$2 + 1]
            Else
                $aRet[$1][$2] = $avSourceArray[$1][$2]
            EndIf
        Next
    Next
    Return SetError(0, 0, $aRet)

EndFunc   ;==>_ArrayDeleteColumn

; #FUNCTION# ====================================================================================================================
; Name...........: _ArrayFindAllex
; Description ...: Searches each element in an array for a value based on supplied parameters.
; Syntax.........: _ArrayFindAll(Byref $avSourceArray,$sSearchString,$iSearchType=1,$iCaseSense=0)
; Parameters ....: $avSourceArray   - [Byref] A 1 dimensional array.
;                  $sSearchString   - The string to search for.
;                  $iSearchType     - 0 = match if element contains the search string
;                                   | 1 = match if element is equal to the search string (default)
;                                   | 2 = match if element starts with the search string
;                                   | 3 = match if element ends with search string
;                   $iCaseSense     - 0 = match is not case sensitive (default)
;                                   | 1 = match is case sensitive
;                   $sSrchArgSepStr - A string of user supplied characters used to seperate multiple search arguments (Default is -1)
; Return values .: Success          - @error is set to 0.  Return a 2D array of
;                                   |     [n][0] - The element number that the string was found in
;                                   |     [n][1] - The search string
;                                   |     [n][2] - The value found at that element
;                  Failure          - @error is set to one of the following:
;                                       1 - Parameter 1 is not an array
;                                   |   2 - Search type is invalid
;                                   |   3 - Case sense is invalid
;                                   |   4 - Source array is more than 2 dimensions
;                                   |   5 - Search string not found
; Author ........: kylomas
; Modified.......: 05/03/2013
; Remarks .......: Version 1.0.0
; Example .......: Yes
; ===============================================================================================================================

Func _ArrayFindAllex(ByRef $avSourceArray, $sSearchString, $iSearchType = 1, $iCaseSense = 0, $sSrchArgSepString = -1)

    ; set parm defaults

    If $iSearchType = Default Or $iSearchType = -1 Then $iSearchType = 1
    If $iCaseSense = Default Or $iCaseSense = -1 Then $iCaseSense = 0
    If $iCaseSense = Default Or $iCaseSense = -1 Then $iCaseSense = 0
    If $sSrchArgSepString = Default Then $sSrchArgSepChar = -1

    ; check parameters

    If Not IsArray($avSourceArray) Then Return SetError(1)
    If $iSearchType < 0 Or $iSearchType > 3 Then Return SetError(2)
    If $iCaseSense <> 0 And $iCaseSense <> 1 Then Return SetError(3)

    ; check for multiple search arguments

    If $sSrchArgSepString <> -1 Then

        If StringInStr($sSearchString, $sSrchArgSepString) > 0 Then
            $aSearchString = StringSplit($sSearchString, $sSrchArgSepString, 3)
        EndIf
    Else
        Local $aSearchString[1]
        $aSearchString[0] = $sSearchString

    EndIf

    ; setup work vars

    Local $sTmp, $iElementNumber = 0, $sSaveSearchString = ''
    If UBound($avSourceArray, 0) = 2 Then Local $aTmp[UBound($avSourceArray, 1) * UBound($avSourceArray, 2) + 80][3]
    If UBound($avSourceArray, 0) = 1 Then Local $aTmp[UBound($avSourceArray, 1) + 80][3]

    For $i = 0 To UBound($aSearchString) - 1

        ; save original search argument, escape reserved characters and construct pattern based on parms

        $sSaveSearchString = $aSearchString[$i]

        $aSearchString[$i] = StringRegExpReplace($aSearchString[$i], '[\^\.\*\?\$\[\]\(\)\\\|]', '\\$0')

        ; construct search argument

        Switch $iSearchType
            Case 0
                If $iCaseSense = 0 Then $aSearchString[$i] = '(?is)' & $aSearchString[$i]
                If $iCaseSense = 1 Then $aSearchString[$i] = '(?s)' & $aSearchString[$i]
            Case 1
                If $iCaseSense = 0 Then $aSearchString[$i] = '(?i)^' & $aSearchString[$i] & '$'
                If $iCaseSense = 1 Then $aSearchString[$i] = '^' & $aSearchString[$i] & '$'
            Case 2
                If $iCaseSense = 0 Then $aSearchString[$i] = '(?is)^' & $aSearchString[$i]
                If $iCaseSense = 1 Then $aSearchString[$i] = '(?s)^' & $aSearchString[$i]
            Case 3
                If $iCaseSense = 0 Then $aSearchString[$i] = '(?is)' & $aSearchString[$i] & '$'
                If $iCaseSense = 1 Then $aSearchString[$i] = '(?s)' & $aSearchString[$i] & '$'
        EndSwitch

        ; main loop

        Switch UBound($avSourceArray, 0)
            Case 1
                For $1 = 0 To UBound($avSourceArray, 1) - 1
                    If StringRegExp($avSourceArray[$1], $aSearchString[$i]) = 1 Then
                        $aTmp[$iElementNumber][0] = $1
                        $aTmp[$iElementNumber][1] = $sSaveSearchString
                        $aTmp[$iElementNumber][2] = $avSourceArray[$1]
                        $iElementNumber += 1
                    EndIf
                Next
            Case 2
                For $1 = 0 To UBound($avSourceArray, 1) - 1
                    For $2 = 0 To UBound($avSourceArray, 2) - 1
                        If StringRegExp($avSourceArray[$1][$2], $aSearchString[$i]) = 1 Then
                            $aTmp[$iElementNumber][0] = 'ROW ' & $1 & ' - ' & 'COL ' & $2
                            $aTmp[$iElementNumber][1] = $sSaveSearchString
                            $aTmp[$iElementNumber][2] = $avSourceArray[$1][$2]
                            $iElementNumber += 1
                        EndIf
                    Next
                Next
            Case Else
                Return SetError(4)
        EndSwitch

    Next

    ; find # of hits

    Local $iRowCount = 0
    For $1 = 0 To UBound($aTmp) - 1
        If StringLen($aTmp[$1][0]) > 0 Then ContinueLoop
        $iRowCount = $1
        ExitLoop
    Next

    ; if string not found @error = 5

    If $iRowCount = 0 Then Return SetError(5)

    ; shrink result array and return results

    ReDim $aTmp[$iRowCount][3]
    Return SetError(0, 0, $aTmp)

EndFunc   ;==>_ArrayFindAllex
#endregion Functions

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to post
Share on other sites

I do not think that will work, unless I read it wrong.

I was thinking you could use the code as an example.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to post
Share on other sites

Thanks for your help @kylomas. I will look at your examples and see if I can get my head around them.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to post
Share on other sites

I came up with this: wondering if I can make it better?

 

#include <array.au3>
;#include <File.au3>

Local $aMain[6] = ['???|abc|downorflapping', _
        '???|abc|down', _
        '???|ccc|ccc', _
        '???|ddd|ddd', _
        '???|xyz|down', _
        '???|xyz|unresponsive']

; create and populate interim 2D array
Local $aAlertInfo[6][3]
For $1 = 0 To UBound($aMain) - 1
    $a10 = StringSplit($aMain[$1], '|')

    $aAlertInfo[$1][0] = $a10[2] ; alert
    $aAlertInfo[$1][1] = $a10[3] ; event
    $aAlertInfo[$1][2] = $a10[1] ; class
Next

_ArrayDisplay($aAlertInfo, 'all')

Local $aNewArray[2][3]
Local $icount = 0, $bPass = True
Local $RemoveWords = 'DownOrFlapping,UnResponsive'

For $x = 0 To UBound($aAlertInfo, 1) - 1
    For $y = 0 To UBound($aAlertInfo, 1) - 1
        If $aAlertInfo[$x][0] = $aAlertInfo[$y][0] And $aAlertInfo[$x][1] <> $aAlertInfo[$y][1] Then
            If StringInStr($RemoveWords, $aAlertInfo[$x][1]) And $aAlertInfo[$x][1] <> 'Down' Then
                $bPass = False
            Else
                $bPass = True
            EndIf
            If Not $bPass Then ContinueLoop
            ;
            If _ArraySearch($aNewArray, $aAlertInfo[$x][0], 0, 0, 0, 0, 1, 1) = -1 Then

                If UBound($aNewArray, 1) > 0 And UBound($aNewArray, 1) <= 2 Then
                    ConsoleWrite('... ' & $icount & '*' & UBound($aNewArray, 1) & @CRLF)
                    ;ConsoleWrite('!> ADD ' & @CRLF)
                    ConsoleWrite(UBound($aNewArray, 1) & @CRLF)
                    $aNewArray[$icount][0] = $aAlertInfo[$x][2] ;class
                    $aNewArray[$icount][1] = $aAlertInfo[$x][0] ;alert
                    $aNewArray[$icount][2] = $aAlertInfo[$x][1] ;event
                    $icount += 1
                    $bPass = False
                EndIf
            EndIf

        ElseIf $aAlertInfo[$y][0] = $aAlertInfo[$x][0] And $aAlertInfo[$y][1] = $aAlertInfo[$x][1] _
                And _ArraySearch($aNewArray, $aAlertInfo[$x][0], 0, 0, 0, 0, 1, 1) = -1 _
                And _ArraySearch($aNewArray, $aAlertInfo[$y][0], 0, 0, 0, 0, 1, 1) = -1 Then

            If StringInStr($RemoveWords, $aAlertInfo[$x][1]) And $aAlertInfo[$x][1] <> 'Down' Then
                $bPass = False
            Else
                $bPass = True
            EndIf
            If Not $bPass Then ContinueLoop
            ;
            $icount += 1
            ReDim $aNewArray[$icount][3]
            ;ConsoleWrite('... ' & $icount & @CRLF)
            ;ConsoleWrite('!> ADD ' & @CRLF)
            $aNewArray[$icount - 1][0] = $aAlertInfo[$x][2]
            $aNewArray[$icount - 1][1] = $aAlertInfo[$x][0] ; need the minus 1 to account for the ZERO index
            $aNewArray[$icount - 1][2] = $aAlertInfo[$x][1]
            $bPass = False

        EndIf
    Next
Next

_ArrayDisplay($aNewArray, 'Unique Alerts')

;_FileWriteFromArray('!testing.txt', $aNewArray)
Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to post
Share on other sites

Assuming that 'downorflapping' and 'unresponsive' come after 'down' if sorted, maybe this can do the work, sort of

#include <array.au3>
;#include <File.au3>

Local $aMain[6] = ['???|abc|downorflapping', _
        '???|abc|down', _
        '???|ccc|ccc', _
        '???|ddd|ddd', _
        '???|xyz|down', _
        '???|xyz|unresponsive']

;_ArrayDisplay($aMain)

_ArraySort($aMain)
;_ArrayDisplay($aMain)

For $i = Ubound($aMain)-1 to 1 step -1
  $current = StringRegExpReplace($aMain[$i], '.+?\|(.*?)\|.+', "$1")
  $prev = StringRegExpReplace($aMain[$i-1], '.+?\|(.*?)\|.+', "$1")
  If $current = $prev Then _ArrayDelete($aMain, $i)
Next
_ArrayDisplay($aMain)
Edited by mikell
Link to post
Share on other sites

That works as long as I change my array to have the second element first and the first element last - not a big deal to change. I did not think the first element would be a problem (stupid me for thinking that), so I chose not to post, but here would be an example:

Local $aMain[6] = ['host|abc|downorflapping', _
        'port|xyz|unresponsive', _
        'host|abc|down', _
        'router|ccc|ccc', _
        'switch|ddd|ddd', _
        'TrunkCable|xyz|down']
I do have a question though, as I understand most of the code. But I am lost when I see REGEXP, the things you guys put in there make me feel like I am reading Greek. I always get lost in those. Can you dumb it down for the none Greek readers?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to post
Share on other sites

That works as long as I change my array to have the second element first and the first element last - not a big deal to change. I did not think the first element would be a problem (stupid me for thinking that), so I chose not to post, but here would be an example:

 

Local $aMain[6] = ['host|abc|downorflapping', _
        'port|xyz|unresponsive', _
        'host|abc|down', _
        'router|ccc|ccc', _
        'switch|ddd|ddd', _
        'TrunkCable|xyz|down']
I do have a question though, as I understand most of the code. But I am lost when I see REGEXP, the things you guys put in there make me feel like I am reading Greek. I always get lost in those. Can you dumb it down for the none Greek readers?

 

 

Can you give an example how the result should look like?

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to post
Share on other sites

So something like this then ?

#include <array.au3>

Local $aMain[6] = ['host|abc|downorflapping', _ 
        'port|xyz|unresponsive', _ 
        'host|abc|down', _ 
        'router|ccc|ccc', _ 
        'switch|ddd|ddd', _ 
        'TrunkCable|xyz|down']

; create and populate interim 2D array
Local $aAlertInfo[6][3]
For $1 = 0 To UBound($aMain) - 1
    $a10 = StringSplit($aMain[$1], '|')

    $aAlertInfo[$1][0] = $a10[2] ; alert
    $aAlertInfo[$1][1] = $a10[3] ; event
    $aAlertInfo[$1][2] = $a10[1] ; class
Next

_ArrayDisplay($aAlertInfo, 'all')
_ArraySort($aAlertInfo) 
_ArrayDisplay($aAlertInfo, 'sorted')

For $i = Ubound($aMain)-1 to 1 step -1
  $current = $aAlertInfo[$i][0] & $aAlertInfo[$i][2] 
  $prev = $aAlertInfo[$i-1][0] & $aAlertInfo[$i-1][2]
  If $current = $prev Then _ArrayDelete($aAlertInfo, $i)
Next
_ArrayDisplay($aAlertInfo)
Link to post
Share on other sites

The list should contain only 4 items, I am trying to remove the duplicates. I just came up with another condition - if only one is in the list it needs to be in the final array.

This is what I am looking for:

 host|abc|down
 router|ccc|ccc
 switch|ddd|ddd
 TrunkCable|xyz|down

But if the list were this:

 ['host|abc|downorflapping', _
        'port|xyz|unresponsive', _
        'router|ccc|ccc', _
        'switch|ddd|ddd', _
        'TrunkCable|xyz|down']

I would want my output to be: Notice how there is not a duplicate (index 2) for abc, so I would still want to pick that one up in my list as well. Meaning, sometimes the alert comes in just with 'downorflapping' and not another one for 'down'. I am still working on this, if anyone has an idea on how to proceed - that would be great.

host|abc|downorflapping
router|ccc|ccc
switch|ddd|ddd _
TrunkCable|xyz|down

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to post
Share on other sites

Is mikell's version not working for you?

I got the same idea:

#include <Array.au3>
Global $aInput[6] = ['host|abc|downorflapping', _
                    'port|xyz|unresponsive', _
                    'host|abc|down', _
                    'router|ccc|ccc', _
                    'switch|ddd|ddd', _
                    'TrunkCable|xyz|down']
$aResult = MakeUnique($aInput)
_ArrayDisplay($aResult)

Func MakeUnique($aInput)
    Local $aWork[UBound($aInput)][3], $i, $x, $aTmp
    For $i = 0 To UBound($aInput) - 1 ;convert it to a 2d array
        $aTmp = StringSplit($aInput[$i], "|", 2)
        For $x = 0 To 2
            $aWork[$i][$x] = $aTmp[$x]
        Next
    Next
    _ArraySort($aWork, 0, 0, 0, 1) ;sort array at subitem 1 (hostnames)
    Local $iUB = UBound($aWork) - 1
    For $i = $iUB To 1 Step - 1 ;delete duplicates
        If $aWork[$i][1] = $aWork[$i - 1][1] Then
            _ArrayDelete($aWork, $i)
        EndIf
    Next
    Return $aWork
EndFunc 

Or a different approach:

#include <Array.au3>
Global $aInput[6] = ['host|abc|downorflapping', _
                    'port|xyz|unresponsive', _
                    'host|abc|down', _
                    'router|ccc|ccc', _
                    'switch|ddd|ddd', _
                    'TrunkCable|xyz|down']
                    
$aResult = MakeUnique($aInput)
_ArrayDisplay($aResult)

Func MakeUnique($aInput)
    Local $sInput = _ArrayToString($aInput, @CRLF)
    Local $aUnique = $aInput, $aTmp, $i, $j, $y
    For $i = 0 To UBound($aInput) - 1
        $aTmp = StringRegExp($sInput, "(.*\|" & StringRegExpReplace($aInput[$i], ".*\|(.*)\|.*", "$1") & "\|.*)", 3)
        If (UBound($aTmp) - 1) > 0 Then
            For $j = 1 To UBound($aTmp) - 1
                For $y = UBound($aUnique) - 1 To 0 Step - 1
                    If $aUnique[$y] = StringReplace(StringStripCR($aTmp[$j]), @LF, "") Then _ArrayDelete($aUnique, $y)
                Next
            Next
        EndIf
    Next
    Return $aUnique
EndFunc

Br,
UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to post
Share on other sites

The version you posted (mike's) seems to work - this does not - posted. Have not had time to look at code...will have time tomorrow, the one you posted, gives me the opposite of what I am looking for, and since I have no idea about REGEX function, it would take me some time to change/fix

#include <array.au3>

Local $aMain[6] = ['host|abc|downorflapping', _
        'port|xyz|unresponsive', _
        'host|abc|down', _
        'router|ccc|ccc', _
        'switch|ddd|ddd', _
        'TrunkCable|xyz|down']

; create and populate interim 2D array
Local $aAlertInfo[6][3]
For $1 = 0 To UBound($aMain) - 1
    $a10 = StringSplit($aMain[$1], '|')

    $aAlertInfo[$1][0] = $a10[2] ; alert
    $aAlertInfo[$1][1] = $a10[3] ; event
    $aAlertInfo[$1][2] = $a10[1] ; class
Next

_ArrayDisplay($aAlertInfo, 'all')
_ArraySort($aAlertInfo)
_ArrayDisplay($aAlertInfo, 'sorted')

For $i = Ubound($aMain)-1 to 1 step -1
  $current = $aAlertInfo[$i][0] & $aAlertInfo[$i][2]
  $prev = $aAlertInfo[$i-1][0] & $aAlertInfo[$i-1][2]
  If $current = $prev Then _ArrayDelete($aAlertInfo, $i)
Next
_ArrayDisplay($aAlertInfo)

Thanks for everyones help

EDIT - I should have said, yours that you posted with the same idea, worked, and appears to be the best...I am looking on how to make sure that the more sever of the two alerts hits, as Down, is a lot more sever then downorflapping, but again will have to work on it tomorrow, thanks again

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By EmilyLove
      I have a string containing the full path of an executable and an array of executables without their paths. I am trying to compare the string to the list in the array and if a match is found, remove it from the array. The entry get removed from the array successfully, and after checking its return result, uses it to update the ubound if it succeeded, but it doesn't want to update to the new value. Any ideas what I am doing wrong? It acts like it is read-only.
      #include <Array.au3> #include <File.au3> Local $sApp_Exe = "F:\App\Nextcloud\nextcloud.exe" Local $aWaitForEXEX = [3, "Nextcloud.exe", "nextcloudcmd.exe", "QtWebEngineProcess.exe"] For $h = 1 To $aWaitForEXEX[0] If StringInStr($sApp_Exe, $aWaitForEXEX[$h]) <> 0 Then $iRet = _ArrayDelete($aWaitForEXEX, $h) If $iRet <> -1 Then $aWaitForEXEX[0] = $iRet ;this line doesn't work. $aWaitForEXEX[0] doesn't update and shortly gives Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.: _ArrayDisplay($aWaitForEXEX) EndIf Next  
    • By vinnyMS
      #Include <Array.au3> #include <Constants.au3> $s = FileRead("2.txt") Local $w = StringRegExp($s, '(?is)(\b\w+\b)(?!.*\b\1\b)', 3) _ArrayColInsert($w, 1) For $i = 0 to UBound($w)-1 StringRegExpReplace($s, '(?i)\b' & $w[$i][0] & '\b', $w[$i][0]) $w[$i][1] = @extended Next _ArraySort($w, 1, 0, 0, 1) _ArrayDisplay($w) i have this script that returns 3 columns  
       
      i need to copy the  Col 0 and Col 1 as text to paste on notepad or excel
      you will have to create a "copy" button if possible
      array.au3 2.txt
    • By DannyJ
      I have a dataset like this, (a strubg)
      Username: User1 Type: Admin RegDate: 1999 Username: User2 Type: User RegDate: 2000 How to make a 2 dimensional array that I can display with _ArrayDisplay?
      This would be a perfect 2D array to represent my data:
      Username           Tpye RegDate User1              Admin 1999 User2              User 2000   If you run this Powershell this powershell command, you can get this dataset that I am talking about:
      Get-LocalUser | Select * With this code you can try it to read into a string:
      #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" #include <Array.au3> ; Just for display in example #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion $sCommand = "powershell.exe Get-LocalUser | Select *" Local $iPid = Run($sCommand, @WorkingDir , @SW_SHOW , $STDOUT_CHILD) ProcessWaitClose($iPid) Local $sOutput = StdoutRead($iPID) ConsoleWrite($sOutput) How can I correctly split $sOutput into a 2D array (with the above mentioned layout) that I can display and I work with?
    • By kovlad
      My solution is to write nested arrays without copying.
      The problem was described hier.
       
      Function:
      #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArrayNestedSet ; Description ...: Assigns a value to an element of a nested 1D array. ; Syntax ........: _ArrayNestedSet(ByRef $aArray, $vIndex, $vValue) ; Parameters ....: $aArray - an array of arrays. ; $vIndex - an index or 1d-array of indexes; ; a size if $vValue not defined (zero to delete). ; $vValue - a value (create, resize or delete if not defined). ; ; Return values .: on success - 1 ; @extended - nesting level of operation ; on failure - 0 ; @extended - nesting level of error ; @error = 1 - invalid array ; @error = 2 - invalid index ; Author ........: ; Modified ......: kovlad ; Remarks .......: ; Related .......: ; Link ..........: https://www.autoitscript.com/forum/topic/185638-assign-a-value-to-an-array-in-array-element/ ; https://www.autoitscript.com/trac/autoit/ticket/3515?replyto=description ; Example .......: Yes ; =============================================================================================================================== Func _ArrayNestedSet(ByRef $aArray, $vIndex, $vValue = Default) Local $extended = @extended + 1 If IsArray($vIndex) Then If UBound($vIndex, 0) <> 1 Then _ Return SetError(2, $extended) If UBound($vIndex) > 1 Then If UBound($aArray, 0) <> 1 Then _ Return SetError(1, $extended) ; keep index for this array Local $i = $vIndex[0] If $i < 0 Or UBound($aArray) <= $i Then _ Return SetError(2, $extended) ; delete index of this array _ArrayDelete($vIndex, 0) ; recursive function call Local $return = _ArrayNestedSet($aArray[$i], $vIndex, $vValue) If @error Then Return SetError(@error, @extended + 1, 0) Else Return SetExtended(@extended + 1, 1) EndIf Else $vIndex = $vIndex[0] EndIf EndIf If $vValue = Default Then If $vIndex < 0 Then _ Return SetError(2, $extended) If $vIndex = 0 Then ; delete array and free memory $aArray = 0 Return SetExtended($extended, 1) EndIf If UBound($aArray, 0) = 1 Then ; resize array keeping data ReDim $aArray[$vIndex] Return SetExtended($extended, 1) Else ; create new nested array Local $aTmp[$vIndex] $aArray = $aTmp Return SetExtended($extended, 1) EndIf Else If UBound($aArray) <= $vIndex Then _ Return SetError(2, $extended + 1) ; set value of array entry $aArray[$vIndex] = $vValue Return SetExtended($extended, 1) EndIf EndFunc  
      Examples:
      ; write value to 1st nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write value to 1st nested array" & @CRLF) Local $aTmp1[4] = [1,2,3,4] _ArrayDisplay($aTmp1, "$aTmp1") Local $aArray[2] = [$aTmp1] ConsoleWrite( _ "_ArrayNestedSet($aArray[0], 3, 14) = " & _ArrayNestedSet($aArray[0], 3, 14) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay($aArray[0], "$aArray[0]") ; resize 1st nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : resize 1st nested array" & @CRLF) ConsoleWrite( _ "_ArrayNestedSet($aArray[0], 8) = " & _ArrayNestedSet($aArray[0], 8) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay($aArray[0], "$aArray[0]") ; write array to 1st nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write array to 1st nested array" & @CRLF) Local $aTmp11[4] = [11,12,13,14] _ArrayDisplay($aTmp11, "$aTmp11") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], 2, $aTmp11) = " & _ArrayNestedSet($aArray[0], 2, $aTmp11) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay(($aArray[0])[2], "($aArray[0])[2]") ; write value to 2nd nested array using index array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write value to 2nd nested array using index array" & @CRLF) Local $aIndex1[2] = [2,3] _ArrayDisplay($aIndex1, "$aIndex1") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex1, 140) = " & _ArrayNestedSet($aArray[0], $aIndex1, 140) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay(($aArray[0])[2], "($aArray[0])[2]") ; resize 2nd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : resize 2nd nested array" & @CRLF) Local $aIndex1[2] = [2,8] _ArrayDisplay($aIndex1, "$aIndex1") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex1) = " & _ArrayNestedSet($aArray[0], $aIndex1) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay(($aArray[0])[2], "($aArray[0])[2]") ; create new 3rd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : create new 3rd nested array" & @CRLF) Local $aIndex2[3] = [2,7,6] _ArrayDisplay($aIndex2, "$aIndex2") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex2) = " & _ArrayNestedSet($aArray[0], $aIndex2) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay((($aArray[0])[2])[7], ")($aArray[0])[2])[7]") ; delete 3rd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : delete 3rd nested array" & @CRLF) Local $aIndex3[3] = [2,7,0] _ArrayDisplay($aIndex3, "$aIndex2") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex3) = " & _ArrayNestedSet($aArray[0], $aIndex3) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF) ConsoleWrite("IsArray((($aArray[0])[2])[7]) = " & IsArray((($aArray[0])[2])[7]) & @CRLF & @CRLF) ; write 0 in 1st nested array to delete the 2nd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write 0 in 1st nested array to delete the 2nd nested array" & @CRLF) Local $aIndex4[1] = [2] _ArrayDisplay($aIndex4, "$aIndex4") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex4, 0) = " & _ArrayNestedSet($aArray[0], $aIndex4, 0) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF) ConsoleWrite("IsArray(($aArray[0])[2]) = " & IsArray(($aArray[0])[2]) & @CRLF & @CRLF) ; delete 1st nested array (same as '$aArray[0] = 0') ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : delete 1st nested array (same as '$aArray[0] = 0')" & @CRLF) Local $aIndex5[1] = [0] _ArrayDisplay($aIndex5, "$aIndex5") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex5) = " & _ArrayNestedSet($aArray[0], $aIndex5) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF) ConsoleWrite("IsArray($aArray[0]) = " & IsArray($aArray[0]) & @CRLF & @CRLF)  
    • By DannyJ
      $sCommands1 = 'powershell.exe Get-ChildItem' $iPid = run($sCommands1   , @WorkingDir , @SW_SHOW , 0x2) $sOutput = ""  While 1     $sOutput &= StdoutRead($iPID)         If @error Then             ExitLoop         EndIf  WEnd ;~ msgbox(0, '' , $sOutput) ConsoleWrite("$sOutput") ConsoleWrite($sOutput) ConsoleWrite(@CRLF) $aOutput = stringsplit($sOutput ,@LF , 2) For $i=0 To  UBound($aOutput) - 1 Step 1     ConsoleWrite($aOutput[$i]) Next The script above reads the whole directory into a one dimensional array, but I need to work with the array, so I need to split the array into multiple dimensions.
      I have already read some forum answers here, and I have already tried these commands:
       
      Are there any way to use the $aOutput variable like in PowerShell:
      PowerShell:
      $a = Get-ChildItem $a.Mode I imagine this in AutoIt  $aOutput
      ConsoleWrite($aOutput[i].Mode) Or if I split this command into 2 dimension like:
      For $i To UBound($aOutput)-1 Step 1 ConsoleWrite($aOutput[$i][1]) ConsoleWrite($aOutput[$i][2]) Next  
×
×
  • Create New...