gcue Posted January 30, 2013 Share Posted January 30, 2013 hello world! i am trying to compare multiple 1d arrays (array amount will always vary) to a master array. Global $master_array[4] = ["3", "red", "yellow", "green"] Global $compare_array1[8] = ["7", "red", "purple", "magenta", "orange", "blue", "yellow", "darkorange"] Global $compare_array2[10] = ["9", "purple", "brickred", "red", "white", "green", "lightblue", "blue", "black", "gray"] Global $compare_array3[7] = ["6", "turquoise", "brown", "magenta", "mustard", "blue", "red"] Global $compare_array4[9] = ["8", "indigo", "lavender", "purple", "red", "gray", "green", "blue", "cyan"] [b]similarities (all arrays have it)[/b] RED - $master_array, $array1, $array2, $array3, $array4 [b]differences (not found in master array and more than one array has it)[/b] PURPLE - $array1, $array2, $array4 BLUE - $array1, $array2, $array3, $array4 etc.. [b]differences (not found in master array and only 1 array has it)[/b] MAGENTA - $array1 ORANGE - $array1 DARKORANGE - $array1 BRICKRED - $array2 WHITE - $array2 etc... this is a pretty complex comparison not sure where to start - especially when comparing any number of arrays thanks in advance! Link to comment Share on other sites More sharing options...
gcue Posted January 30, 2013 Author Share Posted January 30, 2013 sorry the compare arrays are items that come from a listbox - each item pulls a unique array. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 30, 2013 Moderators Share Posted January 30, 2013 gcue, That was fun - I think this does what you want: expandcollapse popup#include <Array.au3> Global $aMaster[4] = ["3", "red", "yellow", "green"] Global $aComp_1[8] = ["7", "red", "purple", "magenta", "orange", "blue", "yellow", "darkorange"] Global $aComp_2[10] = ["9", "purple", "brickred", "red", "white", "green", "lightblue", "blue", "black", "gray"] Global $aComp_3[7] = ["6", "turquoise", "brown", "magenta", "mustard", "blue", "red"] Global $aComp_4[9] = ["8", "indigo", "lavender", "purple", "red", "gray", "green", "blue", "cyan"] ; Concatenate all the arrays to get a full list $aFullList = $aComp_1 _ArrayDelete($aFullList, 0) _ArrayConcatenate($aFullList, $aComp_2, 1) _ArrayConcatenate($aFullList, $aComp_3, 1) _ArrayConcatenate($aFullList, $aComp_4, 1) ; Now only keep the unique items $aUniqueList = _ArrayUnique($aFullList) _ArrayDisplay($aUniqueList, "Unique") ; Look to see if Master items are in all Compare arrays ; Declare an array to hold the common items Global $aCommon[1] = [0] ; Now loop through the Master For $i = 1 To $aMaster[0] ; Check for each Master item $sItem = $aMaster[$i] ; Clear flag $iFound = 0 If _ArraySearch($aComp_1, $sItem) <> -1 Then $iFound += 1 If _ArraySearch($aComp_2, $sItem) <> -1 Then $iFound += 1 If _ArraySearch($aComp_3, $sItem) <> -1 Then $iFound += 1 If _ArraySearch($aComp_4, $sItem) <> -1 Then $iFound += 1 ; Check the flag If $iFound = 4 Then $aCommon[0] += 1 ReDim $aCommon[$aCommon[0] + 1] $aCommon[$aCommon[0]] = $sItem EndIf Next _ArrayDisplay($aCommon, "Common") ; Now look for those items NOT in the Master ; Declare arrays to hold the items not in the master Global $aSingle[1][2] = [[0, 0]] Global $aMultiple[1][2] = [[0, 0]] ; Loop through the Unique array For $i = 1 To $aUniqueList[0] ; Check each item $sItem = $aUniqueList[$i] ; Is it in the Master If _ArraySearch($aMaster, $sItem) <> -1 Then ; Move to next item ContinueLoop EndIf ; Clear a variable to hold the arrays in which the item is found $sFound = "" ; Check each of the other arrays If _ArraySearch($aComp_1, $sItem) <> -1 Then $sFound &= "|" & "1" If _ArraySearch($aComp_2, $sItem) <> -1 Then $sFound &= "|" & "2" If _ArraySearch($aComp_3, $sItem) <> -1 Then $sFound &= "|" & "3" If _ArraySearch($aComp_4, $sItem) <> -1 Then $sFound &= "|" & "4" ; How many | have we got StringReplace($sFound, "|", "") ; And act according to the number of | found Switch @extended Case 0 ; This is never the fired as the list contains all the items in the arrays Case 1 ; Only found in 1 array $aSingle[0][0] += 1 ReDim $aSingle[$aSingle[0][0] + 1][2] $aSingle[$aSingle[0][0]][0] = $sItem $aSingle[$aSingle[0][0]][1] = $sFound Case Else ; Found in more than 1 array $aMultiple[0][0] += 1 ReDim $aMultiple[$aMultiple[0][0] + 1][2] $aMultiple[$aMultiple[0][0]][0] = $sItem $aMultiple[$aMultiple[0][0]][1] = $sFound EndSwitch Next ; And display the results _ArrayDisplay($aSingle, "Single") _ArrayDisplay($aMultiple, "Multiple") Please ask if anything is unclear. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
gcue Posted January 30, 2013 Author Share Posted January 30, 2013 wow im amazed how fast and accurate you are! thank youuuu!! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 30, 2013 Moderators Share Posted January 30, 2013 gcue, And here is how you can do it using loops - which means that after you have initially declared them you can use any number of Compare arrays without changing the code: expandcollapse popup#include <Array.au3> Global $aMaster[4] = ["3", "red", "yellow", "green"] Global $aComp_1[8] = ["7", "red", "purple", "magenta", "orange", "blue", "yellow", "darkorange"] Global $aComp_2[10] = ["9", "purple", "brickred", "red", "white", "green", "lightblue", "blue", "black", "gray"] Global $aComp_3[7] = ["6", "turquoise", "brown", "magenta", "mustard", "blue", "red"] Global $aComp_4[9] = ["8", "indigo", "lavender", "purple", "red", "gray", "green", "blue", "cyan"] ; Put the Compare arrays into another array Global $aCompare[4] = [$aComp_1, $aComp_2, $aComp_3, $aComp_4] ; Concatenate all the arrays to get a full list $aFullList = $aCompare[0] _ArrayDelete($aFullList, 0) For $i = 1 To UBound($aCompare) - 1 _ArrayConcatenate($aFullList, $aCompare[$i], 1) Next ; Now only keep the unique items $aUniqueList = _ArrayUnique($aFullList) _ArrayDisplay($aUniqueList, "Unique") ; Look to see if Master items are in all Compare arrays ; Declare an array to hold the common items Global $aCommon[1] = [0] ; Now loop through the Master For $i = 1 To $aMaster[0] ; Check for each Master item $sItem = $aMaster[$i] ; Clear flag $iFound = 0 For $j = 0 To UBound($aCompare) - 1 If _ArraySearch($aCompare[$j], $sItem) <> -1 Then $iFound += 1 Next ; Check the flag If $iFound = 4 Then $aCommon[0] += 1 ReDim $aCommon[$aCommon[0] + 1] $aCommon[$aCommon[0]] = $sItem EndIf Next _ArrayDisplay($aCommon, "Common") ; Now look for those items NOT in the Master ; Declare arrays to hold the items not in the master Global $aSingle[1][2] = [[0, 0]] Global $aMultiple[1][2] = [[0, 0]] ; Loop through the Unique array For $i = 1 To $aUniqueList[0] ; Check each item $sItem = $aUniqueList[$i] ; Is it in the Master If _ArraySearch($aMaster, $sItem) <> -1 Then ; Move to next item ContinueLoop EndIf ; Clear a variable to hold the arrays in which the item is found $sFound = "" ; Check each of the other arrays For $j = 0 To UBound($aCompare) - 1 If _ArraySearch($aCompare[$j], $sItem) <> -1 Then $sFound &= "|" & $j Next ; How many | have we got StringReplace($sFound, "|", "") ; And act according to the number of | found Switch @extended Case 0 ; This is never the fired as the list contains all the items in the arrays Case 1 ; Only found in 1 array $aSingle[0][0] += 1 ReDim $aSingle[$aSingle[0][0] + 1][2] $aSingle[$aSingle[0][0]][0] = $sItem $aSingle[$aSingle[0][0]][1] = $sFound Case Else ; Found in more than 1 array $aMultiple[0][0] += 1 ReDim $aMultiple[$aMultiple[0][0] + 1][2] $aMultiple[$aMultiple[0][0]][0] = $sItem $aMultiple[$aMultiple[0][0]][1] = $sFound EndSwitch Next ; And display the results _ArrayDisplay($aSingle, "Single") _ArrayDisplay($aMultiple, "Multiple") Again ask if anything is unclear. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2013 Author Share Posted May 30, 2013 gcue,That was fun - I think this does what you want: expandcollapse popup#include <Array.au3> Global $aMaster[4] = ["3", "red", "yellow", "green"] Global $aComp_1[8] = ["7", "red", "purple", "magenta", "orange", "blue", "yellow", "darkorange"] Global $aComp_2[10] = ["9", "purple", "brickred", "red", "white", "green", "lightblue", "blue", "black", "gray"] Global $aComp_3[7] = ["6", "turquoise", "brown", "magenta", "mustard", "blue", "red"] Global $aComp_4[9] = ["8", "indigo", "lavender", "purple", "red", "gray", "green", "blue", "cyan"] ; Concatenate all the arrays to get a full list $aFullList = $aComp_1 _ArrayDelete($aFullList, 0) _ArrayConcatenate($aFullList, $aComp_2, 1) _ArrayConcatenate($aFullList, $aComp_3, 1) _ArrayConcatenate($aFullList, $aComp_4, 1) ; Now only keep the unique items $aUniqueList = _ArrayUnique($aFullList) _ArrayDisplay($aUniqueList, "Unique") ; Look to see if Master items are in all Compare arrays ; Declare an array to hold the common items Global $aCommon[1] = [0] ; Now loop through the Master For $i = 1 To $aMaster[0] ; Check for each Master item $sItem = $aMaster[$i] ; Clear flag $iFound = 0 If _ArraySearch($aComp_1, $sItem) <> -1 Then $iFound += 1 If _ArraySearch($aComp_2, $sItem) <> -1 Then $iFound += 1 If _ArraySearch($aComp_3, $sItem) <> -1 Then $iFound += 1 If _ArraySearch($aComp_4, $sItem) <> -1 Then $iFound += 1 ; Check the flag If $iFound = 4 Then $aCommon[0] += 1 ReDim $aCommon[$aCommon[0] + 1] $aCommon[$aCommon[0]] = $sItem EndIf Next _ArrayDisplay($aCommon, "Common") ; Now look for those items NOT in the Master ; Declare arrays to hold the items not in the master Global $aSingle[1][2] = [[0, 0]] Global $aMultiple[1][2] = [[0, 0]] ; Loop through the Unique array For $i = 1 To $aUniqueList[0] ; Check each item $sItem = $aUniqueList[$i] ; Is it in the Master If _ArraySearch($aMaster, $sItem) <> -1 Then ; Move to next item ContinueLoop EndIf ; Clear a variable to hold the arrays in which the item is found $sFound = "" ; Check each of the other arrays If _ArraySearch($aComp_1, $sItem) <> -1 Then $sFound &= "|" & "1" If _ArraySearch($aComp_2, $sItem) <> -1 Then $sFound &= "|" & "2" If _ArraySearch($aComp_3, $sItem) <> -1 Then $sFound &= "|" & "3" If _ArraySearch($aComp_4, $sItem) <> -1 Then $sFound &= "|" & "4" ; How many | have we got StringReplace($sFound, "|", "") ; And act according to the number of | found Switch @extended Case 0 ; This is never the fired as the list contains all the items in the arrays Case 1 ; Only found in 1 array $aSingle[0][0] += 1 ReDim $aSingle[$aSingle[0][0] + 1][2] $aSingle[$aSingle[0][0]][0] = $sItem $aSingle[$aSingle[0][0]][1] = $sFound Case Else ; Found in more than 1 array $aMultiple[0][0] += 1 ReDim $aMultiple[$aMultiple[0][0] + 1][2] $aMultiple[$aMultiple[0][0]][0] = $sItem $aMultiple[$aMultiple[0][0]][1] = $sFound EndSwitch Next ; And display the results _ArrayDisplay($aSingle, "Single") _ArrayDisplay($aMultiple, "Multiple")Please ask if anything is unclear. M23i am using this version.. =)i am trying to get the colors that are unique to master..so in this case:Global $aMaster[6] = ["5", "forestgreen", "red", "yellow", "green", "fusia"] Global $aComp_1[8] = ["7", "red", "purple", "magenta", "orange", "blue", "yellow", "darkorange"] Global $aComp_2[10] = ["9", "purple", "brickred", "red", "white", "green", "lightblue", "blue", "black", "gray"] Global $aComp_3[7] = ["6", "turquoise", "brown", "magenta", "mustard", "blue", "red"] Global $aComp_4[9] = ["8", "indigo", "lavender", "purple", "red", "gray", "green", "blue", "cyan"]forestgreen and fusia are the colors that are unique to master...i tried to determine those colors here but it didnt workIf _ArraySearch($aComp_1, $sItem) <> -1 Then $iFound += 1 else msgbox(0,"",$sitem) endif Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 30, 2013 Moderators Share Posted May 30, 2013 gcue, Add this to the script: ; Look to see if Master items are in no Compare arrays ; Declare an array to hold the Master-Only items Global $aMaster_Only[1] = [0] ; Now loop through the Master For $i = 1 To $aMaster[0] ; Check for each Master item If _ArraySearch($aUniqueList, $aMaster[$i]) = -1 Then $aMaster_Only[0] += 1 ReDim $aMaster_Only[$aMaster_Only[0] + 1] $aMaster_Only[$aMaster_Only[0]] = $aMaster[$i] EndIf Next _ArrayDisplay($aMaster_Only, "Master Only") And you will get an array of colours that are only found in the master list. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2013 Author Share Posted May 30, 2013 works great!thank you VERY much Melba =) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 30, 2013 Moderators Share Posted May 30, 2013 gcue, My pleasure as always. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now