Forum Moderators: open
So with the Dictionary.Script I would load all my data as the keys, and a random value.
This will ensure that there is no duplicate data and I can then somehow loop through and retrieve the data again?
But how do I loop through it if the key is non numeric? Seems like it would be difficult to get my data back out...
<%@ Language="VBScript" %>
<% OPTION EXPLICIT %>
<%
Function RemoveDupsAndOutput()
Dim myArray, myDict, indexSet myDict = CreateObject("Scripting.Dictionary")
myArray = Split("red,orange,yellow,green,blue,indigo,violet,green,green,green,green",",")
for index = 0 to UBound(myArray)
if ( not myDict.Exists(myArray(index)) ) then
myDict.Add myArray(index), myArray(index)
Response.Write myDict(myArray(index)) + "<br>"
end if
next
End Function
%>
<html>
<head>
<title>DupCheck</title></head>
<body>
<% RemoveDupsAndOutput() %>
</body>
</html>
So basically, you'd have your array, and insert into the dictionary, checking before each insert if the key already exists..
HTH,
Mark
But how do I loop through it if the key is non numeric
Its a collection, so you use a collection-friendly loop :)
for each key in objDict
response.write objDict.Item(key)
next
I dont think you need to worry about checking if the key exists each time you insert, just insert them and let the container work for you, preventing duplicates etc.