Newbie question:Passing a byte

FFMan

Member
Licensed User
Longtime User
this doesn't compile Astreams.Write(13)

as the compiler assumes the 13 is a double and therefore doesn't match the required byte argument type.

In VB it would type convert, in other languages you could put say 13% to indicate an integer.

Whats the android equivelent please ?
 

FFMan

Member
Licensed User
Longtime User
ok i understand. so if i write strBytes(1)=13 then that will work, but given that i have in the lines before put a longer string into strByes() how can I tell astreams.write where in the array to stop sending. How does it know how long the string is as i have dimensioned it to 99 elements ?

Indeed if I have
strBytes = conv.StringToBytes(DateTime.Now,"UTF8")
Astreams.Write(strBytes)

how is the end marked as I don't think all 99 bytes are being sent each time, unless the rest contains nulls which i can't see in the display label and all 99 are being sent. If thats the case can i dimension the array to size every pass ?

thanks
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Learned this from Erel:

B4X:
Astreams.Write(Array As Byte(13))

Rolf
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
How does it know how long the string is as i have dimensioned it to 99 elements
B4X:
Dim strBytes(99) as Byte
' strBytes holds a reference (pointer) to an array(99)

strBytes = conv.StringToBytes(DateTime.Now,"UTF8")
' strBytes now points to a new array of whatever length
' the previous array will be garbage collected
 
Upvote 0
Top