B4R Question byteconvertor indexof is returning 255 instead of -1 in b4r?

thetahsk

Active Member
Licensed User
Longtime User
Your declaration is wrong . It must be

B4X:
Dim s() as Byte ="1-0:1.8.1(003808.351*kWh)"
log(bc.IndexOf(s,"*m3)"))  ' return -1
 
Upvote 0

MbedAndroid

Active Member
Licensed User
Longtime User
9
20
24
255
as result of
B4X:
    Dim s()  As Byte="1-0:1.8.1(003808.351*kWh)"
   Dim start=bc.IndexOf(s,"(") As Byte
   Dim stop=bc.IndexOf(s,"*kW") As Byte
   Dim closingparenthesis=bc.IndexOf(s,")") As Byte
   Dim gas=bc.IndexOf(s,"*m3)") As Byte
   Log(start)
   Log(stop)
   Log(closingparenthesis)
   Log(gas)
changing it to:
B4X:
    Dim s()  As Byte="1-0:1.8.1(003808.351*kWh)"
   Dim start As Byte=bc.IndexOf(s,"(")
   Dim stop=bc.IndexOf(s,"*kW") As Int
   Dim closingparenthesis=bc.IndexOf(s,")") As Int
   Dim gas As Byte=bc.IndexOf(s,"*m3)")
   Log(start)
   Log(stop)
   Log(closingparenthesis)
   Log(gas)
makes no difference
int or byte are Uint and U8 in my case
 
Upvote 0

MbedAndroid

Active Member
Licensed User
Longtime User
Log(bc.IndexOf(s,"*m3)") )
reports -1
are bytes only Unsigned in b4R?

B4X:
    Dim gas As Byte=(bc.IndexOf(s,"*m3)") )
   Log(gas)
   gas=-1
   Log(gas)
output:
255
255

changing byte to int gives the correct result, so byte=unsigned
 
Last edited:
Upvote 0
Top