Jump to content

Need some help getting data from an Array


RickB75
 Share

Recommended Posts

Guys,

        I'm kinda stumped on how to get the correct data from this array. What I need: I need to a unique array containing unique data from the items in position 0 and position 2. I know I can use _ArrayUnique but that is only for a single column. I need an array that basically unique using two identifiers. Column 0 and column 2. Can you guys help??

 

#include <Array.au3>
#include <String.au3>

Local $aTemp [0][2]
Local $avArray[10][3] = [["1234A","a","2016"],["4321A","b","2016"],["2354B","c","2017"],["6524A","b","2016"],["1234A","a","2017"],["6524A","a","2016"],["1234A","b","2016"],["2354B","c","2017"],["5896A","b","2016"],["5469B","a","2017"]]

_ArrayDisplay($avArray)

 

Link to comment
Share on other sites

I know this loop structure isn't correct. But I am trying :)

Local $aTemp [0][2]
Local $avArray[10][3] = [["1234A","a","2016"],["4321A","b","2016"],["2354B","c","2017"],["6524A","b","2016"],["1234A","a","2017"],["6524A","a","2016"],["1234A","b","2016"],["2354B","c","2017"],["5896A","b","2016"],["5469B","a","2017"]]

_ArrayDisplay($avArray)

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

    MsgBox(0,'data ' & $i, $avArray[$i][0] & ' ' & $avArray[$i][2])

        $index = _Arraysearch($aTemp,$avArray[$i][0])

                If @error = 3 or 6 Then

                    $aTemp[$i][0] = $avArray[$i][0]
                    $aTemp[$i][1] = $avArray[$i][2]

                ElseIf $index >= 0 Then

                    If $aTemp[0][1] <> $avArray[$i][2] Then

                        $aTemp[0][0] = $avArray[$i][0]
                        $aTemp[0][1] = $avArray[$i][2]


                    EndIf

                EndIf


    Next


_ArrayDisplay($aTemp)

 

Link to comment
Share on other sites

This is a possible solution:

#include <Array.au3>


Global $aTable[][] = [["1234A","a","2016"],["4321A","b","2016"],["2354B","c","2017"],["6524A","b","2016"],["1234A","a","2017"],["6524A","a","2016"],["1234A","b","2016"],["2354B","c","2017"],["5896A","b","2016"],["5469B","a","2017"]]

_ArrayDisplay($aTable)

For $i=UBound($aTable)-1 to 0 Step -1
    For $j = $i-1 To 0 Step -1
        If $aTable[$i][0] = $aTable[$j][0] Then
            If $aTable[$i][2] = $aTable[$j][2] Then _
                _ArrayDelete($aTable,$j)
        EndIf
    Next
Next

_ArrayDisplay($aTable, "Result")


Sorry codetag didn't working.

Edited by Melba23
Added code tags
Link to comment
Share on other sites

another...

#include <Array.au3>

Global $aTable[][] = [["1234A","a","2016"],["4321A","b","2016"],["2354B","c","2017"],["6524A","b","2016"],["1234A","a","2017"],["6524A","a","2016"],["1234A","b","2016"],["2354B","c","2017"],["5896A","b","2016"],["5469B","a","2017"]]

local $aTMP[ubound($aTable)]

for $i = 0 to ubound($aTable) - 1
    $aTMP[$i] = $aTable[$i][0] & $aTable[$i][2]
Next

_arraydisplay(_arrayunique($aTMP))

 

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 comment
Share on other sites

What my initial approach was is to loop through the array and grab each item in the determined positions and then compare them. It never crossed my mind to combine them and then compare them. Thank you both for your examples and insight. Both of them work. In this situation, @kylomas yours perfectly fitted into my main script with only minor edits to the main script.  

 

Thank you @AutoBert and @kylomas for chiming in and helping me!! It is very very much appreciated!!! 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...