Sign in to follow this  
Followers 0
kor

help with recursive loop search

11 posts in this topic

#1 ·  Posted (edited)

I have 6 inputs I'm reading in using a loop.

For $i = 1 To UBound($aInput) - 1
$aRead[$i] = GUICtrlRead($aControls[$aInput[$i]])
Next

without posting the entire code just assume the above loop already works. It gives me all 6 inputs.

What I need to do is then compare each input with every other input. So for example if Input1="test" and Input2="test" I need throw an error.

Basically all 6 inputs must be unique and none of them can contain the value of any of the others.

Trying to figure out how I can write that kind of statement. Do I need to do a loop within a loop or where might I begin?

EDIT: forgot to mention that technically the inputs can be null. So if input2 and input3 are both null that is fine as long as if they did have values they are not the same.

Edited by kor

Share this post


Link to post
Share on other sites



Hi, kor. Have you tried just using _ArrayUnique, to have the duplicates stripped out for you, rather than trying to loop through them all?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

I looked at ArrayUnique but I don't actually need the unique values, I need to know if the values are repeated. ArrayUnique doesn't look like it offers any way to return a value that would tell me that it has stripped values from the array because they are not unique.

Share this post


Link to post
Share on other sites

kor,

Just compare the sizes of the arrays with UBound after you have run _ArrayUnique - the same size means all original items were unique, different sizes means you had some matches. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I can't just know if the arrays are different sizes.

I need to know which input is the same as the other

If Input 2 and Input 5 are the same value I need to know.

It's not as simple as just knowing if all values are unique or not, if they are not unique I need to know and throw an error for the input that is duplicated.

Edited by kor

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

you can make a temp array, that is equal to your control array, and then do:

redim $tempArray[7]

or 6, depending on if 0 based

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Kor,

Or something like this

#include <array.au3>

local $aInputs[5] = ['tom','john','george','alex','john']

local $st = timerinit()
local $sDiff = _FindDups($aInputs)
consolewrite('time to run func = ' & round(timerdiff($st)/1000,4) & @lf)

func _FindDups($array)

    for $i = 0 to ubound($array) - 1
        if isdeclared('s' & $array[$i]) then
            consolewrite('Dup found at element = ' & $i & ' dup value = ' & $array[$i] & @lf)
        else
            assign('s' & $array[$i],1)
        endif
    Next

endfunc

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

Share this post


Link to post
Share on other sites

@kylomas, that works great!

Is there a way to also know the original element that the duplicate is from?

IE, you use $i as the location of where the duplicate exists, but is there a way to determine at what index the original is from (or at least the first usage of it in the index?)

IE, if elements 2 and 5 are the same, then $i would be 5... but is there a way to get the index of element 2?

Share this post


Link to post
Share on other sites

Seems to me you already have it in post #7

Just show both loop indexes plus one, and if you want the values, in the output display. Why only show one index?

Share this post


Link to post
Share on other sites

Kor,

Yes. I adapted this from some really slick code that spiff59 posted sometime ago dealing with a similar task. I am not at a real machine, however, so cannot reference that code and am kind of pressed for time. Take the code that I posted apart and I'm sure yo can figure it out.

Good Luck,

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

Share this post


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
Sign in to follow this  
Followers 0