Wish Type testing in Select - case block

knutf

Active Member
Licensed User
Longtime User
I wish that this code:
B4X:
Sub Process_Globals
    Type t1(memberX As String)
    Type t2(memberY As String)
End Sub

Sub TypeTesting(o As Object)
    If o Is t1 Then
        Log("t1")
    else if o Is t2 Then
        Log("t2")
    End If   
End Sub

...could be written like this:

B4X:
Sub Process_Globals
    Type t1(memberX As String)
    Type t2(memberY As String)
End Sub

Sub TypeTesting(o As Object)
    Select o 
        case Is t1
            Log("t1")
        case Is t2
            Log("t2")
    End Select
End Sub

...or like this:

B4X:
Sub Process_Globals
    Type t1(memberX As String)
    Type t2(memberY As String)
End Sub

Sub TypeTesting(o As Object)
    Select o is
        case t1
            Log("t1")
        case t2
            Log("t2")
    End Select
End Sub

https://www.b4x.com/android/forum/threads/is-testing-type-in-select-case-possible.98278/
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
You can restructure your select case to be more like your wish:
B4X:
'
Select Case True
     Case o Is T1
          Log("t1 type")
     Case o Is T2
          Log("t2 type")
     Case else
          Log("unhandled type")
End Select
 
Top