We help IT Professionals succeed at work.

arrays

smollah
smollah asked
on
Medium Priority
250 Views
Last Modified: 2010-05-02
I'm creating an array. I'm reading in 30 numbers, each of which is between 20 and 100. As I input each number, I only want it to print if it is not a duplicate. Would I use a one-dimensional array?
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2012

Commented:
A one-dimensional array is sufficient.

Function InArray(arr() as Long, X As Long) As Boolean
Dim I As Integer
Dim Done As Boolean

InArray = False      'Assume not found

Done = True
I = LBound(arr)
Do While Not Done
   If X = arr(I) Then
      Done = True
      InArray = True
   ElseIf I = UBound(Arr) Then
      Done = True
   Else
      I = I + 1
   End If
Loop
     
End Function

Anthony
Commented:
FilterDuplicates: http://www.vb2themax.com/Item.asp?PageID=CodeBank&ID=81
(uses a fact that collection doesn't accept duplicate keys)

Author

Commented:
Thanks for the quick reply!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.