Jump to content

Array and getting rid of dupes


nitekram
 Share

Recommended Posts

I have read and tried to follow along with the ones I have found here but they are not working for me, as maybe I do not understand

This looks like it would work, but does not

Can someone help and either explain why my logic is wrong or help me find a better way

#include <Array.au3>

Dim $aArray[7] = [21,21,22,23,24,25,27], $TempArray[52]
Dim $aArray2 = $aArray
Local $Count = 0
_ArraySort($aArray2)
_ArrayDisplay($aArray2, " DIND STRAIGHT")
    For $i = 0 To UBound($aArray) - 1
        For $j = 0 To UBound($aArray) - 1
            If StringRight($aArray2[$i],2) <> StringRight($aArray[$j],2) Then
                
                $TempArray[$Count] = $aArray[$j]
                MsgBox('', $aArray[$i], $aArray2[$j])
                _ArrayDisplay($TempArray)
                $Count += 1
            EndIf
        Next
    Next
    
    _ArrayDisplay($TempArray)

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

OK, but explain what you you want to do?

I want to have another array with no dupes

I got it like this, but still might be a better way.

#include <Array.au3>

Dim $aArray[7] = [21, 21, 22, 23, 24, 25, 27], $TempArray[7]
Dim $aArray2 = $aArray
Local $Count = 0
_ArraySort($aArray2)
_ArrayDisplay($aArray2, " DIND STRAIGHT")
For $i = 0 To UBound($aArray) - 1
    For $j = 0 To UBound($aArray) - 1
        If _ArraySearch($TempArray, $aArray2[$i]) Then
            If @error = 6 Then
                MsgBox('', '', '')
                
                $TempArray[$Count] = $aArray2[$i]
                MsgBox('', $aArray[$i], $aArray2[$j])
                _ArrayDisplay($TempArray)
                $Count += 1
            EndIf
        EndIf
    Next
Next

_ArrayDisplay($TempArray)

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

Look in help file about _ArrayFindAll().

That finds them, but what I wanted was a new array with only the ones without a match

Now, the other question, how do I find the one with the matches and put them, including the dupes only into another array

so if i had 21,21,22,22,24,25,27 the new array would contain 21,21,22,22 only

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

That finds them, but what I wanted was a new array with only the ones without a match

Now, the other question, how do I find the one with the matches and put them, including the dupes only into another array

so if i had 21,21,22,22,24,25,27 the new array would contain 21,21,22,22 only

#include <Array.au3>

Dim $aArray[7] = [21,21,22,22,24,25,27]
Dim $aNew[7]
$COUNT = 0
For $INDEX = 0 To UBound($aArray)-1
    $FIND = _ArrayFindAll($aArray,$aArray[$INDEX])
    If UBound($FIND) > 1 Then 
        $aNew[$COUNT] = $aArray[$INDEX]
        $COUNT +=1
    EndIf
Next

_ArrayDisplay($aNew)

When the words fail... music speaks.

Link to comment
Share on other sites

#include <Array.au3>

Dim $aArray[7] = [21,21,22,22,24,25,27]
Dim $aNew[7]
$COUNT = 0
For $INDEX = 0 To UBound($aArray)-1
    $FIND = _ArrayFindAll($aArray,$aArray[$INDEX])
    If UBound($FIND) > 1 Then 
        $aNew[$COUNT] = $aArray[$INDEX]
        $COUNT +=1
    EndIf
Next

_ArrayDisplay($aNew)
That works great - thank you very much!

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

Another version for you to look at

#include <Array.au3>

Dim $aArray[7] = [21, 21, 22, 23, 24, 25, 27], $TempArray[7]
Dim $aArray2 = $aArray
Local $Count = 0
_ArraySort($aArray2)
_ArrayDisplay($aArray2, " DIND STRAIGHT")
$TempArray[0] = $aArray2[0]
For $i = 1 To UBound($aArray) - 1
    If $TempArray[$Count] <> $aArray2[$i] Then
        $Count += 1
        $TempArray[$Count] = $aArray2[$i]
    EndIf
Next
ReDim $TempArray[$Count + 1] ; Remove the empty array elements
_ArrayDisplay($TempArray)

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

_ArrayUnique() ... do a search on the forum for it.

I looked at that, but it kept giving me an error about wrong arguments.

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

  • Moderators

I looked at that, but it kept giving me an error about wrong arguments.

Not sure how you managed that:
#include <array.au3>
Dim $aArray[7] = [21,21,22,23,24,25,27]
_ArrayUnique($aArray)
_ArrayDisplay($aArray)

Func _ArrayUnique(ByRef $aArray, $vDelim = '', $iBase = 0, $iCase = 0)
    If Not IsArray($aArray) Then Return SetError(1, 0, 0)
    If $vDelim = '' Then $vDelim = Chr(1)
    Local $sHold = ""
    For $iCC = $iBase To UBound($aArray) - 1
        If Not StringInStr($vDelim & $sHold, $vDelim & $aArray[$iCC] & $vDelim, $iCase) Then
            $sHold &= $aArray[$iCC] & $vDelim
        EndIf
    Next
    $sHold = StringTrimRight($sHold, StringLen($vDelim))
    If $sHold And $iBase = 1 Then
        $aArray = StringSplit($sHold, $vDelim)
        Return SetError(0, 0, $aArray)
    ElseIf $sHold And $iBase = 0 Then
        $aArray = StringRegExp($sHold & $vDelim, "(?s)(.+?)" & $vDelim, 3)
        Return SetError(0, 0, $aArray)
    EndIf
    Return SetError(2, 0, 0)
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Not sure how you managed that:

#include <array.au3>
Dim $aArray[7] = [21,21,22,23,24,25,27]
_ArrayUnique($aArray)
_ArrayDisplay($aArray)

Func _ArrayUnique(ByRef $aArray, $vDelim = '', $iBase = 0, $iCase = 0)
    If Not IsArray($aArray) Then Return SetError(1, 0, 0)
    If $vDelim = '' Then $vDelim = Chr(1)
    Local $sHold = ""
    For $iCC = $iBase To UBound($aArray) - 1
        If Not StringInStr($vDelim & $sHold, $vDelim & $aArray[$iCC] & $vDelim, $iCase) Then
            $sHold &= $aArray[$iCC] & $vDelim
        EndIf
    Next
    $sHold = StringTrimRight($sHold, StringLen($vDelim))
    If $sHold And $iBase = 1 Then
        $aArray = StringSplit($sHold, $vDelim)
        Return SetError(0, 0, $aArray)
    ElseIf $sHold And $iBase = 0 Then
        $aArray = StringRegExp($sHold & $vDelim, "(?s)(.+?)" & $vDelim, 3)
        Return SetError(0, 0, $aArray)
    EndIf
    Return SetError(2, 0, 0)
EndFunc
This must have been a version that I did not see - the ones I worked with had _ArraySort($aTemp, 0, 1, $aTemp[0][0], 2, 0)

and I kept getting errors -

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 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...