Sign in to follow this  
Followers 0
Fran

Duplicate value in array

3 posts in this topic

#1 ·  Posted (edited)

Wonder if someone can help me with this please... my brain is in Friday-mode ;)

I have an array that I want to check for duplicate values and then warn the user. Below is an example extract from my code:

$sArray = StringSplit("123,456,789,321,654,789,987", ",")
$cntSamples = $sArray[0]

;if <there is a duplicated value in the array> then
MsgBox(4096, "Error", "There are duplicate values in the array.") ;and echo the value

EDIT: I'm sorry for posting on this forum.. I didn't realise when I made the post. And now I don't know how to delete this and post on the general forum. :)

Edited by Fran

Share this post


Link to post
Share on other sites



I would use something like this:

#include <array.au3>
$aArray = StringSplit("123,456,789,321,654,789,987", ",")
_ArrayDisplay($aArray)

; Only tells if there are differences
$aNewArray = _ArrayUnique($aArray, 1, 1)
_ArrayDisplay($aNewArray)
If $aArray[0] <> $aNewArray[0] Then MsgBox(4096, "Error", "There are duplicate values in the array.")

; Shows the duplicate values
_ArraySort($aArray, 0, 1)
_ArrayDisplay($aArray)
For $index = 1 To $aArray[0]-1
    If $aArray[$index] = $aArray[$index+1] Then MsgBox(4096, "Error", "Value '" & $aArray[$index] & "' is a duplicate value in the array")
Next

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

You are legend! Thank you ;)

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