Hamo Member Licensed User Longtime User Feb 21, 2015 #1 I am trying to declare and initialize a byte array like this dim ba(4) as byte = 1,2,3,4 Is there a way of doing this without ba(0) = 1 ba(1) = 2 ba(2) = 3 ba(3) = 4 Hamo
I am trying to declare and initialize a byte array like this dim ba(4) as byte = 1,2,3,4 Is there a way of doing this without ba(0) = 1 ba(1) = 2 ba(2) = 3 ba(3) = 4 Hamo
S sorex Expert Licensed User Longtime User Feb 21, 2015 #2 in B4A you need to do it in 2 steps. this might work B4X: dim ba() as byte ba=array as byte (1,2,3,4) Upvote 0
in B4A you need to do it in 2 steps. this might work B4X: dim ba() as byte ba=array as byte (1,2,3,4)
Hamo Member Licensed User Longtime User Feb 21, 2015 #3 This works but I was looking for a more direct way Dim bc As ByteConverter Dim s As String dim PacketToSend(16) as byte s = "83c20014ffffff00ffffff00ffffff00" PacketToSend = bc.HexToBytes(s) Hamo Upvote 0
This works but I was looking for a more direct way Dim bc As ByteConverter Dim s As String dim PacketToSend(16) as byte s = "83c20014ffffff00ffffff00ffffff00" PacketToSend = bc.HexToBytes(s) Hamo
S sorex Expert Licensed User Longtime User Feb 21, 2015 #4 that needs an additional library, mine doesn't. Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Feb 22, 2015 #6 sorex said: in B4A you need to do it in 2 steps. Click to expand... You need one step: B4X: Dim b() As Byte = Array As Byte(1, 2, 3, 4, 0xff, 0xab) Last edited: Feb 22, 2015 Upvote 0
sorex said: in B4A you need to do it in 2 steps. Click to expand... You need one step: B4X: Dim b() As Byte = Array As Byte(1, 2, 3, 4, 0xff, 0xab)
S sorex Expert Licensed User Longtime User Feb 22, 2015 #7 thanks for the hint, Erel. I remember that we discussed this on the chat 2.5 years ago and we couldn't get it to work like that. So I kept using that 2 step method. It must've been that 2nd byte definition that we didn't use and used B4X: Dim b() As Byte = (1, 2, 3, 4, 0xff, 0xab) What's the reason to define the byte (and array) twice? Last edited: Feb 22, 2015 Upvote 0
thanks for the hint, Erel. I remember that we discussed this on the chat 2.5 years ago and we couldn't get it to work like that. So I kept using that 2 step method. It must've been that 2nd byte definition that we didn't use and used B4X: Dim b() As Byte = (1, 2, 3, 4, 0xff, 0xab) What's the reason to define the byte (and array) twice?
Erel B4X founder Staff member Licensed User Longtime User Feb 22, 2015 #8 B4X: Dim i As Int = 5 We declare a variable of type int and assign the value 5 to this variable. B4X: Dim b() As Byte = Array As Byte(1, 2, 3, 4, 0xff, 0xab) We declare a variable of type "array of bytes" and assign an array of bytes to it. Upvote 0
B4X: Dim i As Int = 5 We declare a variable of type int and assign the value 5 to this variable. B4X: Dim b() As Byte = Array As Byte(1, 2, 3, 4, 0xff, 0xab) We declare a variable of type "array of bytes" and assign an array of bytes to it.
S sorex Expert Licensed User Longtime User Feb 22, 2015 #9 but in a lot of languages () already means it's an array. I, and probably others aswell, read that line as "b as array of bytes=array as byte(1,2..)" so it's declared twice. b is declared to expect bytes so the "array as byte" is kind of overkill. (unless it opens doors for some wicked stuff) Upvote 0
but in a lot of languages () already means it's an array. I, and probably others aswell, read that line as "b as array of bytes=array as byte(1,2..)" so it's declared twice. b is declared to expect bytes so the "array as byte" is kind of overkill. (unless it opens doors for some wicked stuff)
Erel B4X founder Staff member Licensed User Longtime User Feb 22, 2015 #10 Array As <type>(...) is not a declaration. It is a shorthand syntax to create arrays. You can use it in any place that expects an array (or list). B4X: For Each i As Int In Array As Int(1, 2,3) Log(i) List1.AddAll(Array As String("a", "b")) Upvote 0
Array As <type>(...) is not a declaration. It is a shorthand syntax to create arrays. You can use it in any place that expects an array (or list). B4X: For Each i As Int In Array As Int(1, 2,3) Log(i) List1.AddAll(Array As String("a", "b"))