Results 1 to 3 of 3

Thread: In Array Operator?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    Posts
    7
    Does anyone know if there is any operator that works like SQL's in operator?

    Something like
    Dim FarmAnimals(10) as string
    If "Hen" Not In FarmAnimals Then FarmAnimals(1) = "Hen"


    Thanks,
    Bob

  2. #2
    Guest
    Try this.

    Code:
    Dim FarmAnimals(10) As String
    Dim IsIn As Boolean
    
    'Loop though all of the valus in FarmAnimals
    For i = 0 To 10
        'If it's "Hen" then IsIn = True
        If FarmAnimals(i) = "Hen" Then IsIn = True
    Next i
    
    'If Hen is not already in the Array then add it
    If IsIn = False Then FarmAnimals(1) = "Hen"

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    You can do the same thing quicker with a collection
    Code:
        Dim sDummy As String
        Dim bFound As Boolean
        Dim FarmAnimals As Collection
        
        On Error Resume Next
        
        'If the text is in the collection, Err = 0, otherwise it's not
        sDummy = FarmAnimals.Item("Hen")
        bFound = (Err = 0)
        If bFound Then
            Err.Clear
            MsgBox "Already in collection"
        Else
            FarmAnimals.Add "Hen", "Hen"
        End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width