Code correction

rfsingh81

Member
Licensed User
Longtime User
Hello, can someone advise how to correct the following code:
B4X:
Sub AStream_NewData (Buffer() As Byte)
   Dim aaya() As Byte
   aaya=BytesToString (Buffer, 0, Buffer.Length, "UTF8")
   If aaya ="A" Then
      Btn1.Color=Colors.RGB(128,255,128)
   Else
      Btn1.Color=Colors.RGB(255,128,128)
   End If
End Sub

This gives me compilation error.
Cheers.
 

rfsingh81

Member
Licensed User
Longtime User
Thanks. Another question

Thanks. It worked.
Could you please also help me with a situation if the incoming information is not just an "A" but "abcde". Cheers
 
Upvote 0

rfsingh81

Member
Licensed User
Longtime User
I believe it is the same.

Thanks. What I mean is how would you work out the following:
With 1 String it works fine -
B4X:
If aaya ="A" Then
            Btn1.Color=Colors.RGB(0,255,0)
            Btn1.TextColor=Colors.RGB(139,0,0)
         Else
            Btn1.Color=Colors.RGB(139,0,0)
            Btn1.TextColor=Colors.RGB(0,255,0)
         End If
But I have 6 buttons. I tried this but it didn't worked:
B4X:
If aaya(0) ="A" Then
            Btn1.Color=Colors.RGB(0,255,0)
            Btn1.TextColor=Colors.RGB(139,0,0)
         Else
            Btn1.Color=Colors.RGB(139,0,0)
            Btn1.TextColor=Colors.RGB(0,255,0)
         End If
If aaya(1) ="B" Then '.....and so on for 6 buttons
            Btn2.Color=Colors.RGB(0,255,0)
            Btn2.TextColor=Colors.RGB(139,0,0)
         Else
            Btn2.Color=Colors.RGB(139,0,0)
            Btn2.TextColor=Colors.RGB(0,255,0)
         End If
In the first example only "A" comes in.
In the second example the incoming data is is ABcdef.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Do you know what is the value in the string and the length?
What does your string look like?

If it is: aaya = "ABCDE", you can do the following, but it depends that each charachter is at the right place.

B4X:
If aaya.Char(0) ="A" Then
            Btn1.Color=Colors.RGB(0,255,0)
            Btn1.TextColor=Colors.RGB(139,0,0)
         Else
            Btn1.Color=Colors.RGB(139,0,0)
            Btn1.TextColor=Colors.RGB(0,255,0)
         End If
If aaya.Char(1) ="B" Then '.....and so on for 6 buttons
            Btn1.Color=Colors.RGB(0,255,0)
            Btn1.TextColor=Colors.RGB(139,0,0)
         Else
            Btn1.Color=Colors.RGB(139,0,0)
            Btn1.TextColor=Colors.RGB(0,255,0)
         End If
 
Upvote 0
Top