Gianni Sassanelli Active Member Licensed User Longtime User Jul 27, 2018 #1 Does b4a support in operator like SQL IN OPERATOR? for Example: Code: Copy If RoleName in ( "Val1", "Val2" ,"Val2" ) Then 'Go End If Instead of: Code: Copy If RoleName = "Val1" Or RoleName = "Val2" Or RoleName = "Val2" Then 'Go End If thanks Last edited: Jul 27, 2018
Does b4a support in operator like SQL IN OPERATOR? for Example: Code: Copy If RoleName in ( "Val1", "Val2" ,"Val2" ) Then 'Go End If Instead of: Code: Copy If RoleName = "Val1" Or RoleName = "Val2" Or RoleName = "Val2" Then 'Go End If thanks
M Mahares Expert Licensed User Longtime User Jul 27, 2018 #2 Gianni Sassanelli said: If RoleName in ( "Val1", "Val2" ,"Val2" ) Then 'Go End If Click to expand... You can do this: Code: Copy 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 Upvote 0
Gianni Sassanelli said: If RoleName in ( "Val1", "Val2" ,"Val2" ) Then 'Go End If Click to expand... You can do this: Code: Copy 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
LucaMs Expert Licensed User Longtime User Jul 27, 2018 #3 Use a List. Code: Copy Dim lstValues As List lstValues.Initialize2(Array As String("Val1", "Val2", "Val3")) If lstValues.IndexOf("Val2") <> - 1 Then ' ... End If Maps also can be used: If mapValues.ContainsKey... Upvote 0
Use a List. Code: Copy Dim lstValues As List lstValues.Initialize2(Array As String("Val1", "Val2", "Val3")) If lstValues.IndexOf("Val2") <> - 1 Then ' ... End If Maps also can be used: If mapValues.ContainsKey...
M Mahares Expert Licensed User Longtime User Jul 27, 2018 #4 LucaMs said: Dim lstValues As List lstValues.Initialize2(Array As String("Val1", "Val2", "Val3")) If lstValues.IndexOf("Val2") <> - 1 Then ' ... End If Click to expand... I do not think your solution is correct because he is looking for more than just Val2. He is looking for Val1 or Val2 or val3 Upvote 0
LucaMs said: Dim lstValues As List lstValues.Initialize2(Array As String("Val1", "Val2", "Val3")) If lstValues.IndexOf("Val2") <> - 1 Then ' ... End If Click to expand... I do not think your solution is correct because he is looking for more than just Val2. He is looking for Val1 or Val2 or val3
LucaMs Expert Licensed User Longtime User Jul 27, 2018 #5 Mahares said: I do not think your solution is correct because he is looking for more than just Val2. He is looking for Val1 or Val2 or val3 Click to expand... ??? I wrote: If lstValues.IndexOf("Val2") <> - 1 Then but, of course, he can write: If lstValues.IndexOf(RoleName) <> - 1 Then getting the same of: Gianni Sassanelli said: If RoleName in ( "Val1", "Val2" ,"Val2" ) Then Click to expand... or: Gianni Sassanelli said: If RoleName = "Val1" Or RoleName = "Val2" Or RoleName = "Val2" Then Click to expand... Upvote 0
Mahares said: I do not think your solution is correct because he is looking for more than just Val2. He is looking for Val1 or Val2 or val3 Click to expand... ??? I wrote: If lstValues.IndexOf("Val2") <> - 1 Then but, of course, he can write: If lstValues.IndexOf(RoleName) <> - 1 Then getting the same of: Gianni Sassanelli said: If RoleName in ( "Val1", "Val2" ,"Val2" ) Then Click to expand... or: Gianni Sassanelli said: If RoleName = "Val1" Or RoleName = "Val2" Or RoleName = "Val2" Then Click to expand...
Erel B4X founder Staff member Licensed User Longtime User Jul 29, 2018 #6 Yes: Code: Copy 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 Upvote 0
Yes: Code: Copy 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
LucaMs Expert Licensed User Longtime User Jul 29, 2018 #7 or: Code: Copy Sub IsIn(value As Object, items As List) As Boolean Return items.IndexOf(value) > -1 End Sub It should work even with objects (even with instances of our classes or of custom types). Upvote 0
or: Code: Copy Sub IsIn(value As Object, items As List) As Boolean Return items.IndexOf(value) > -1 End Sub It should work even with objects (even with instances of our classes or of custom types).
M Mahares Expert Licensed User Longtime User Jul 29, 2018 #8 Erel said: If IsIn("Val1", Array("Val1", "Val2", "Val3")) Then Log("Yes") End If Click to expand... When you use the IN operator in SQLite, you use a code like this: Code: Copy 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: Code: Copy 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. Upvote 0
Erel said: If IsIn("Val1", Array("Val1", "Val2", "Val3")) Then Log("Yes") End If Click to expand... When you use the IN operator in SQLite, you use a code like this: Code: Copy 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: Code: Copy 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.
LucaMs Expert Licensed User Longtime User Jul 29, 2018 #9 The question was: Gianni Sassanelli said: Does b4a support in operator like SQL IN OPERATOR? Click to expand... "Does b4a support", which means: "is there a function similar to...?" The "in" SQL (not SQLite operator) is: So, the "b4a equivalent function" is exactly what Erel wrote (just after my great suggestion ) Upvote 0
The question was: Gianni Sassanelli said: Does b4a support in operator like SQL IN OPERATOR? Click to expand... "Does b4a support", which means: "is there a function similar to...?" The "in" SQL (not SQLite operator) is: So, the "b4a equivalent function" is exactly what Erel wrote (just after my great suggestion )
LucaMs Expert Licensed User Longtime User Jul 29, 2018 #10 Mahares said: But @Erel and @LucaMs are presenting only one value: Val1. Click to expand... Maybe I can explain better what I mean so: Mahares said: curs=Starter.SQL1.ExecQuery2("SELECT * FROM tblVehicles WHERE make IN (?,?,?) ORDER BY Make", _ Array As String("Val1","Val2","Val3") ) Click to expand... You also are comparing just one value, here: the current value of "make" (or, better, the value of "make" of the "current" (each) record. Upvote 0
Mahares said: But @Erel and @LucaMs are presenting only one value: Val1. Click to expand... Maybe I can explain better what I mean so: Mahares said: curs=Starter.SQL1.ExecQuery2("SELECT * FROM tblVehicles WHERE make IN (?,?,?) ORDER BY Make", _ Array As String("Val1","Val2","Val3") ) Click to expand... You also are comparing just one value, here: the current value of "make" (or, better, the value of "make" of the "current" (each) record.
M Mahares Expert Licensed User Longtime User Jul 29, 2018 #11 LucaMs said: You also are comparing just one value, here: the current value of "make" Click to expand... 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: Code: Copy 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. Upvote 0
LucaMs said: You also are comparing just one value, here: the current value of "make" Click to expand... 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: Code: Copy 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.
LucaMs Expert Licensed User Longtime User Jul 29, 2018 #12 Mahares said: 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 Click to expand... 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. Upvote 0
Mahares said: 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 Click to expand... 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.
Gianni Sassanelli Active Member Licensed User Longtime User Jul 30, 2018 #13 Erel said: Yes: Code: Copy 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 Click to expand... tank's Erel Upvote 0
Erel said: Yes: Code: Copy 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 Click to expand... tank's Erel
Gianni Sassanelli Active Member Licensed User Longtime User Jul 30, 2018 #14 Mahares said: You can do this: Code: Copy 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 Click to expand... thank's Upvote 0
Mahares said: You can do this: Code: Copy 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 Click to expand... thank's
Gianni Sassanelli Active Member Licensed User Longtime User Jul 30, 2018 #15 LucaMs said: Maybe I can explain better what I mean so: You also are comparing just one value, here: the current value of "make" (or, better, the value of "make" of the "current" (each) record. Click to expand... thank's Upvote 0
LucaMs said: Maybe I can explain better what I mean so: You also are comparing just one value, here: the current value of "make" (or, better, the value of "make" of the "current" (each) record. Click to expand... thank's