Newbie problem

FFMan

Member
Licensed User
Longtime User
Just trying to get to grips with B4a, though I am proficient in VB6 and ZBASIC code, the android way is a little different but i am enjoying the learning.

I am converting the bluetooth serial example to use astreams as suggested as i couldn't find published complete code, just some extracts.

The receive section using astreams works, and so does the send if i leave it as textwriter but i guess i should use astreams for send too for reasons stated. the problem is more with stringtobytes, this just won't compile

B4X:
Sub btnSend_Click
   Dim strBytes(9) As Byte
   If connected Then
      strBytes() = StringToBytes(txtSend.Text,"UTF8")
      Astreams.Write(strBytes())
      
      'TextWriter1.WriteLine(txtSend.Text)
      'TextWriter1.Flush
      txtSend.Text = ""
   End If
End Sub

i've added the byteconverter library (though i'm, not sure if this is required as the bytestostring call in the receive routine compiles OK without this library for some reason).

i'm sure i'm missing something basic here :signOops: any help much appreciated.
 

FFMan

Member
Licensed User
Longtime User
thanks but i get

Error description: Missing parameter.
Occurred on line: 72
strBytes() = conv.StringToBytes(txtSend.Text,"UTF8")
Word: (

the pop-up help shows only 2 parameters required.

Also, out of interest why does the BytesToString in the receive routine not have to be declared and structured the same way. Is this a core function perhaps ?
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Sorry, I modified your code without looking at it closely. Remove the parentheses from the array assignment.
B4X:
strBytes[B][COLOR="Red"]()[/COLOR][/B] = conv.StringToBytes(txtSend.Text,"UTF8")

BytesToString is a intrinsic language keyword. ByteConverter is an object on which you need to invoke methods.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…