Sorex,
Thanks for your reply.
Although I was unable to create an array or list of byte arrays like I was trying to do, I did implement a version of your suggestion.
Instead of strings, I created a byte array of 10 "groups" of 16 bytes (three displayed in this post) and merely grabbed 16 byte segments from within, based upon an "offset".
This became:
then in code I "grab" the "segment" I want based upon an offset.
B4X:
' look up the encryption key within the integer array
Sub LoadKey(KeyNo As Int) As Byte()
Dim Ky(16) As Byte 'create a temporary byte array
Bconv.ArrayCopy(Keys, KeyNo*16, Ky, 0, 16) 'copy the correct 16 bytes to the array
Return Ky
End Sub
The returned Ky contains a byte array of 16 bytes that I use for encryption. This gives me a selectable key value based upon the KeyNo requested. Seems to work well.
I posted this in case someone was wondering if this was solved.
If anyone knows how to make an array of byte arrays, I'd be curious if there is a more elegant way to do this.
Thanks,
Rusty
Dim listOfArrays As List
listOfArrays.Initialize
listOfArrays.Add(Array As Byte(0, 1, 2, 3))
listOfArrays.Add(Array As Byte(4, 5, 6, 7))
Dim bytes() As Byte = listOfArrays.Get(1)
I suppose it's not going to happen...
As far as I know, VB and VBA are the only languages that have that option.
The "standard" is to indicate the number of items (#items) you need in the declaration, and this will give you an array with indexes from 0 to #items-1.
It's possible to declare your array with 1 item more and never use the item at index 0
Hello,
I would like to create programmatically the following command :
B4X:
aStream.Write(Array As Byte (2,Asc("?"),Asc("s"),Asc("t"),3,Asc("3"),Asc("5")))
how can i convert a list to byte array ? i try this :
B4X:
Dim cmdSecv As List
Dim b() As Byte
cmdSecv.Initialize
'lblRez.Text= Bit.ToHexString(crc8(cmd))
'calculatedCRC = Bit.ToHexString(crc8(cmd))
'Log(calculatedCRC.Length)
cmdSecv.Add(2)
cmdSecv.Add(Asc("?"))
cmdSecv.Add(Asc("s"))
cmdSecv.Add(Asc("t"))
cmdSecv.Add(3)
cmdSecv.Add(Asc("3"))
cmdSecv.Add(Asc("5"))
Log(cmdSecv)
'aStream.Write(Array As Byte (2,Asc("?"),Asc("s"),Asc("t"),3,Asc("3"),Asc("5")))
'b=cmdSecv
aStream.Write(Array As Byte (cmdSecv))