Jump to content

Recommended Posts

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
Posted

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.

  • Moderators
Posted

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

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
Posted

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

Posted

@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?

Posted

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

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
  • Recently Browsing   0 members

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