B4R Question select case with byte array

Tayfur

Well-Known Member
Licensed User
Longtime User
I used case statement with byte array;

why dont work it?

B4X:
Log(bc.SubString2(Data,2,5))'>>> return >>>C01
    Select bc.SubString2(Data,2,5)
        Case "C01".GetBytes
            Log("C01") ' dont work this line
        Case "C02".GetBytes
            Log("C02")
        Case "C03".GetBytes
            Log("C03")
        Case "C04".GetBytes
            Log("C04")
        Case "C05".GetBytes
            Log("C05")
           Case Else
                Log("Else") '>>>> works this line
     
    End Select
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code will work:
B4X:
Select bc.StringFromBytes(bc.SubString2(data,2,5))
   Case "C01"
     Log("C01") ' dont work this line
   Case "C02"
     Log("C02")
   Case "C03"
     Log("C03")
   Case "C04"
     Log("C04")
   Case "C05"
     Log("C05")
   Case Else
     Log("Else") '>>>> works this line
End Select

Select Case works with objects. The data about the array is lost when the array is casted to an object. So it does an identity comparison. It might be changed in the future.
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
This code will work:
B4X:
Select bc.StringFromBytes(bc.SubString2(data,2,5))
   Case "C01"
     Log("C01") ' dont work this line
   Case "C02"
     Log("C02")
   Case "C03"
     Log("C03")
   Case "C04"
     Log("C04")
   Case "C05"
     Log("C05")
   Case Else
     Log("Else") '>>>> works this line
End Select

Select Case works with objects. The data about the array is lost when the array is casted to an object. So it does an identity comparison. It might be changed in the future.
thanks for helps...
 
Upvote 0
Top