arrays

This is a discussion on arrays within the Inetserver forums in Microsoft Tools category; I have a collection of objects that may have duplicates in it. What I want to do is to iterate through the list and only add the non duplicates to an array, so as I am adding to the array, I need some way of checking against the current contents of the array. Is this possible, or is there a better way to do this? *** Sent via Developersdex http://www.developersdex.com ***...

Go Back   Application Development Forum > Microsoft Tools > Inetserver

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-08-2008, 10:24 AM
Mike P
Guest
 
Default arrays

I have a collection of objects that may have duplicates in it. What I
want to do is to iterate through the list and only add the non
duplicates to an array, so as I am adding to the array, I need some way
of checking against the current contents of the array. Is this
possible, or is there a better way to do this?



*** Sent via Developersdex http://www.developersdex.com ***
Reply With Quote
  #2  
Old 08-08-2008, 10:48 AM
Jon Paal [MSMD]
Guest
 
Default Re: arrays

you could use a dictionary and the 'exists' method

The following examples illustrate the use of the Exists method.

[JScript]
function keyExists(k)
{
var fso, s = "";
d = new ActiveXObject("Scripting.Dictionary");
d.Add("a", "Athens");
d.Add("b", "Belgrade");
d.Add("c", "Cairo");
if (d.Exists(k))
s += "Specified key exists.";
else
s += "Specified key doesn't exist.";
return(s);
}[VBScript]
Function KeyExistsDemo
Dim d, msg ' Create some variables.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens" ' Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
If d.Exists("c") Then
msg = "Specified key exists."
Else
msg = "Specified key doesn't exist."
End If
KeyExistsDemo = msg
End Function


Reply With Quote
  #3  
Old 08-08-2008, 10:49 AM
Bob Barrows [MVP]
Guest
 
Default Re: arrays

Mike P wrote:
> I have a collection of objects that may have duplicates in it. What I
> want to do is to iterate through the list and only add the non
> duplicates to an array, so as I am adding to the array, I need some
> way of checking against the current contents of the array. Is this
> possible, or is there a better way to do this?
>
>
>

There's no shortcut. You need to do a nested loop.


start loop through collection
within the collection loop, loop through the array checking to see if object
already exists.
if not, add the object to the array and move to the next object

Do you need more detail than that? if so, we sill need more details.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 05:10 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.