Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate Array Function Help 1

Status
Not open for further replies.

ncar35b

Technical User
Jan 10, 2003
55
US
Hello, I'm trying to use this function to find out if an array has duplicates. When duplicates exist, the result is true.


<%
Private Function HasDups(byVal arrayinput)
dim wkarray, j, i, l
wkarray = arrayinput
for j = 0 to ubound( wkarray )
l = 0
for i = 0 to ubound( wkarray )
if wkarray(i) = wkarray(j) then l = l + 1
if l > 1 then
HasDups = True
Exit function
end if
next
next
HasDups = False
End Function
%>


When I use the function like this:

response.write HasDups(array(testone, testtwo, testthree, testone)) -- the result is true.

However when I try to use a string:

testString = "testone, testtwo, testthree, testone"
response.write HasDups(array(testString)) the result is false.

It should be true, since the array has a dupe!

Any idea why this happens?

 
The Array() function doesn't work like that. This
Code:
Array("testone", "testtwo", "testthree", "testone")
will result in a four-member array, with element 0 containing "testone", but this
Code:
Array("testone, testtwo, testthree, testone")
will result in a one-member array, with element 0 containing "testone, testtwo, testthree, testone". It's easy to test:
Code:
Response.Write(UBound(Array("testone, testtwo, testthree, testone")))
 
Oh, and if you really wanted to pass your testString to your function as an array, you could do:
Code:
response.write HasDups(Split(testString, ", "))
I believe.
 
Thanks Genimuse, is there any way to take my four-member array:

testString = "testone, testtwo, testthree, testone"

and make it into a one member array so it will work?
 
Thanks Genimuse, you beat me to it!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top