Dim RoleName As String
Select RoleName
Case "Val1", "Val2" ,"Val3"
'do something
Log("my choice")
Case Else
'do something else
Log("not my choice")
End Select
If IsIn("Val1", Array("Val1", "Val2", "Val3")) Then
Log("Yes")
End If
Sub IsIn(value As String, items As List) As Boolean
Return items.IndexOf(value) > -1
End Sub
When you use the IN operator in SQLite, you use a code like this:
B4X:
curs=Starter.SQL1.ExecQuery2("SELECT * FROM tblVehicles WHERE make =? OR make=? OR make=? ORDER BY Make", _
Array As String("Val1","Val2","Val3") )
or this code:
B4X:
curs=Starter.SQL1.ExecQuery2("SELECT * FROM tblVehicles WHERE make IN (?,?,?) ORDER BY Make", _
Array As String("Val1","Val2","Val3") )
But @Erel and @LucaMs are presenting only one value: Val1. Do you have to run your function for each of Val1, Val2 and Val3. I still do not see the logic behind your code when the thread question is looking for any of the 3 values. Please explain.
Your statement is true, but the value can be any one of; "Val1", "Val2", or "Val3". Do you have to run your function for each of Val1, Val2 and Val3.
Does your function need to run this code 3 times:
B4X:
If IsIn("Val1", Array("Val1", "Val2", "Val3")) Then
Log("Yes")
End If
If IsIn("Val2", Array("Val1", "Val2", "Val3")) Then
Log("Yes")
End If
If IsIn("Val3", Array("Val1", "Val2", "Val3")) Then
Log("Yes")
End If
Perhaps it is best to wait and see what the creator of the thread intended to mean. If he is in tune with yours and Erel's solution, I will stand corrected.
Your statement is true, but the value can be any one of; "Val1", "Val2", or "Val3". Do you have to run your function for each of Val1, Val2 and Val3.
Does your function need to run this code 3 times
Why? I just need (he needs) to know if a value is IN a list of values or, saying it in a "reverse way", if a list of values contains a specific (specified) value.
The difference with SQL is that you perform this check on each record of a table.
If IsIn("Val1", Array("Val1", "Val2", "Val3")) Then
Log("Yes")
End If
Sub IsIn(value As String, items As List) As Boolean
Return items.IndexOf(value) > -1
End Sub
Dim RoleName As String
Select RoleName
Case "Val1", "Val2" ,"Val3"
'do something
Log("my choice")
Case Else
'do something else
Log("not my choice")
End Select