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
Printable View
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
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"
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