Jump to content

_arraydiff()


Recommended Posts

#include<array.au3>
;Test to find the difference between the 2 arrays

dim $array1[8] = ["a","b","d","f","h","j","k","l"]
dim $array2[13] = ["a","b","c","d","e","f","g","h","i","j","k","l","m"]
dim $array3[ubound($array2)]
dim $total[1]
$a=0


;copy $array2 as i want it kept
for $ct=0 to ubound($array2)-1
    $array3[$ct]=$array2[$ct]
Next

;mark $array3 with a blank array ("") for deletion if found
for $c = 0 to UBound($array2)-1
    $sea=_ArraySearch($array1,$array2[$c],0,0)
    if @error=0 then 
$array3[$c]=""
    EndIf
Next

;delete all "" entries
for $d=0 to UBound($array3)-1
if $array3[$d]<>"" Then
    $total[$a]=$array3[$d]
    $a+=1
if $d<UBound($array3)-1 then ReDim $total[$a+1]
EndIf
Next

;display
_ArrayDisplay($total)

this works for me, anyone know an easier way......

Edited by Aceguy
Link to comment
Share on other sites

#include<array.au3>
;Test to find the difference between the 2 arrays

dim $array1[8] = ["a","b","d","f","h","j","k","l"]
dim $array2[13] = ["a","b","c","d","e","f","g","h","i","j","k","l","m"]
dim $array3[ubound($array2)]
dim $total[1]
$a=0


;copy $array2 as i want it kept
for $ct=0 to ubound($array2)-1
    $array3[$ct]=$array2[$ct]
Next

;mark $array3 with a blank array ("") for deletion if found
for $c = 0 to UBound($array2)-1
    $sea=_ArraySearch($array1,$array2[$c],0,0)
    if @error=0 then 
$array3[$c]=""
    EndIf
Next

;delete all "" entries
for $d=0 to UBound($array3)-1
if $array3[$d]<>"" Then
    $total[$a]=$array3[$d]
    $a+=1
if $d<UBound($array3)-1 then ReDim $total[$a+1]
EndIf
Next

;display
_ArrayDisplay($total)

this works for me, anyone know an easier way......

You can copy an array like this

Dim $arrayA[3] = [1,2,3]

$CopyA = $arrayA.

Your function doesn't find the differences between the 2 arrays; it only finds the values in $array2 which are not in $array1 but there could be values in $array1 which are not in $array2. Perhaps that's what you want but I thought that it was worth saying.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

#include<array.au3>
;Test to find the difference between the 2 arrays

dim $array1[8] = ["a","b","d","f","h","j","k","l"]
dim $array2[13] = ["a","b","c","d","e","f","g","h","i","j","k","l","m"]
dim $array3[ubound($array2)]
dim $total[1]
$a=0


;copy $array2 as i want it kept
for $ct=0 to ubound($array2)-1
    $array3[$ct]=$array2[$ct]
Next
Well, to start with, you don't have to copy an array one element at a time. Just "Dim $array3 = $array2" would have done it.

;mark $array3 with a blank array ("") for deletion if found
for $c = 0 to UBound($array2)-1
    $sea=_ArraySearch($array1,$array2[$c],0,0)
    if @error=0 then 
$array3[$c]=""
    EndIf
Next

;delete all "" entries
for $d=0 to UBound($array3)-1
if $array3[$d]<>"" Then
    $total[$a]=$array3[$d]
    $a+=1
if $d<UBound($array3)-1 then ReDim $total[$a+1]
EndIf
Next

;display
_ArrayDisplay($total)

this works for me, anyone know an easier way......

Why change the element and then go back again to delete it? In fact, why work with $array3 at all? Just loop through the first array checking against the second array, and assembling a delimited string of unique values (diffs). One StringSplit() at the end produce your output array.

^_^

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

thansk for the info guys, i have learnt lots....

#include<array.au3>
;Test to find the difference between the 2 arrays

dim $array1[8] = ["a","b","d","f","h","j","k","l"]
dim $array2[13] = ["a","b","c","d","e","f","g","h","i","j","k","l","m"]

;mark $array3 with a blank array ("") for deletion if found
$array3=""
for $c = 0 to UBound($array2)-1
    $sea=_ArraySearch($array1,$array2[$c],0,0)
    if @error=6 then 
$array3&=$array2[$c]&","
    EndIf
Next

;reconstruct & display
$ss=StringSplit($array3,",")
_ArrayDelete($ss,UBound($ss)-1)
_ArrayDisplay($ss)

Your function doesn't find the differences between the 2 arrays; it only finds the values in $array2 which are not in $array1 but there could be values in $array1 which are not in $array2. Perhaps that's what you want but I thought that it was worth saying.

thats the way i wanted it, so thanks for mentionioning. ^_^

$array2 must remain untouched. they are files in a folder to be processed, and $array1 is the ones that have already been processed at a previous time.... so needed to find the ones that havent been done

Ty for all your help tho.... whats the limit for the size of an array.....

Edited by Aceguy
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...