Android Question [B4X] shorter if

Alexander Stolte

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

B4X:
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
 

angel_

Well-Known Member
Licensed User
Longtime User
Maybe this:
B4X:
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

Sandman

Expert
Licensed User
Longtime User
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?
B4X:
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

Mahares

Expert
Licensed User
Longtime User
Here is my 2 cents worth in my suitCASE or briefCASE:
B4X:
Select 5
        Case  1, 2, 3, 4, 5, 6
            Log("I am here")
        Case Else
            Log("I don't exist")
    End Select
 
Upvote 0
Top