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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate Keys in Dictionary

Status
Not open for further replies.

travisbrown

Technical User
Dec 31, 2001
1,016
So I can't figure this out. This should work, but it's allowing a duplicate key. I don't know how since it should throw an error, but the output is showing two of the same key.

I've got two arrays and trying to add them together in a dictionary, then into a MD array
Code:
Dim d
Set d=Server.CreateObject("Scripting.Dictionary")
	
IF isArray(existing_array) THEN
	FOR i = 0 TO UBOUND(existing_array,2)
 		IF d.Exists(existing_array(0,i)) = TRUE THEN
	 		d.Remove(existing_array(0,i))
	 	END IF
		 d.Add existing_array(0,i),existing_array(1,i)
	NEXT
END IF
	'add new resources, check for duplicates	
IF isArray(new_array) THEN
	FOR i = 0 TO UBOUND(new_array,2)
		IF d.Exists(new_array(0,i)) = TRUE THEN
			d.Remove(new_array(0,i))
		END IF
			d.Add new_array(0,i),new_array(1,i)
		NEXT
	END IF

dictionary_size = d.count-1
	
DIM arrResourceArray()
REDIM arrResourceArray(2,dictionary_size)
	
a = d.keys
FOR i = 0 TO dictionary_size
	arrResourceArray(0,i) = a(i)
	arrResourceArray(1,i) = d.item(arrResourceArray(0,i))
	response.write a(i) & "<br />"
NEXT

OUTPUT:
200
1007
1339
1534
1534
 
[1] The script by itself should work except minor precision.
>REDIM arrResourceArray(2,dictionary_size)
[tt]REDIM arrResourceArray([red]1[/red],dictionary_size)[/tt]

[2] With this one may find the duplicates are not.
[tt] response.write a(i) & " : " & escape(a(i)) & "<br />"[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top