How to check for duplicates when creating an array? 
Author Message
 How to check for duplicates when creating an array?

Hello, I want to create an array without duplicate numbers,
how to check for duplicates....?

regards Jorgen

dim nr(7)
for x=1 to 7
randomize
nr(x) = 1 + round(rnd()*(9-1+1))
response.write nr(x) & "<br>"
next



Fri, 01 Jul 2005 02:43:02 GMT  
 How to check for duplicates when creating an array?

Quote:

> Hello, I want to create an array without duplicate numbers,
> how to check for duplicates....?

> dim nr(7)
> for x=1 to 7
> randomize
> nr(x) = 1 + round(rnd()*(9-1+1))
> response.write nr(x) & "<br>"
> next

Use the Scripting.Dictionary maybe?

' get 7 unique numbers

Set oDic = CreateObject("Scripting.Dictionary")
x = 0

Do
  Randomize
  iNr = 1 + round(rnd()*(9-1+1))
  If Not oDic.Exists(iNr) Then
    oDic.Add iNr, Null
    x = x + 1
  End If
Loop Until x = 7

For Each iNr In oDic
 response.write iNr & "<br>"
Next

--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and a ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter



Fri, 01 Jul 2005 04:03:17 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. duplicates in array in VBScript

2. Deleting duplicate array values

3. How to check if control is a part of an array (without checking err.number)

4. Real-time checking of duplicate entries

5. before saving a record, check duplicate entries

6. Duplicated record check

7. Checking if a record is duplicated before adding or during adding it to a table

8. Checking for duplicate records

9. Checking For Duplicate Entries using VBA

10. Checking for Duplicates

11. duplicate checking error

12. Checking duplicate records

 

 
Powered by phpBB® Forum Software