B4R Question Add value to array of bytes

BaGRoS

Active Member
Licensed User
Longtime User
Hi
I working on small project, and looking for couple of solution.
One of them is how add value to array, it's simple
B4X:
Private data(8) As Byte = "05-09-05"
after add 1 to value 09, should be 10.
I wrote some code:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
   
    Private data(8) As Byte = "05-09-05"
    Private bc As ByteConverter
   
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
   
   
    Log(data)
   
    Dim a As Byte
    Dim position As Byte = 3
    Dim value As String = NumberFormat(bc.StringFromBytes(bc.SubString2(data,position,position + 2)) + 1, 2, 0)
    Dim array_value(2) As Byte = bc.StringToBytes(value)
       
    For a=0 To array_value.Length -1
       
        data(position + a) = array_value(a)
       
    Next
   
    Log(data)
   
End Sub
and this working well, I think...

But I always looking for different way, maybe more simple way?
Some help in optimisation? Very welcome.
 
Top