Android Question [B4X] shorter if

Alexander Stolte

Expert
Licensed User
Longtime User
hey, can this be simplified somehow?

B4X: Copy
If tmp_m.Get("type") = 1 Or tmp_m.Get("type") = 2 Or tmp_m.Get("type") = 3 Or tmp_m.Get("type") = 4 Or tmp_m.Get("type") = 5 Or tmp_m.Get("type") = 6 Or tmp_m.Get("type") = 7 Or tmp_m.Get("type") = 8 Then
                
Log("test")           
                
End If
 
Maybe this:
B4X: Copy
Dim tipo As String = tmp_m.Get("type")
Dim Lista As List = Array As String(1, 2, 3, 6, 7, 8, 20)
Log(Lista.IndexOf("" & tipo) > -1)
 
Upvote 0
In theory it might be possible to do something like this. Doesn't work though, IndexOf isn't supported by arrays. Perhaps there's an alternative way of writing this that works?
Code: Copy
If (Array As String(1, 2, 3, 6, 7, 8, 20)).IndexOf(tmp_m.Get("type")) > -1 Then
   ' Code goes here
End If
 
Upvote 0
Here is my 2 cents worth in my suitCASE or briefCASE:
Code: Copy
Select 5
        Case  1, 2, 3, 4, 5, 6
            Log("I am here")
        Case Else
            Log("I don't exist")
    End Select
 
Upvote 0
Back
Top