B4R Question Substring2, last element error

Mostez

Well-Known Member
Licensed User
Longtime User
Hello,
I load 100 bytes from binary file to an array, then split it into fields, the problem is i always get wrong last element, in this case i get 0xB2 instead of 0x00, any ideas?

Thanks

B4X:
Sd.Position = 0
    If Sd.OpenRead(filename) = True Then
        Sd.Stream.ReadBytes(cb,0,100) 'read 100 bytes
        Sd.close
        Dim IDCardInFile(10) As Byte = BC.SubString2(cb,0,10)
        Dim UserID(16) As Byte = BC.SubString2(cb,11,27)
        Dim Description1 (20) As Byte = BC.SubString2(cb,28,48)
        Dim Description2 (20) As Byte = BC.SubString2(cb,49,67)
        Dim IssueDate (12) As Byte = BC.SubString2(cb,70,82)
        Dim ExpiryDate (12) As Byte = BC.SubString2(cb,83,95)
        Dim CheckExpiry (1) As Byte = BC.SubString2(cb,96,97)
        Dim IsExpiredorDisabled (1) As Byte = BC.SubString2(cb,98,99)
        Dim DoorOpen (1) As Byte= BC.SubString2(cb,100,101)

        Log( IDCardInFile)
        Log(  UserID)
        Log(  Description1)
        Log(  Description2 )
        Log(  IssueDate)
        Log(  ExpiryDate)
        Log(  BC.HexFromBytes(CheckExpiry))
        Log(   BC.HexFromBytes(IsExpiredorDisabled) )
        Log(   BC.HexFromBytes(DoorOpen ))
 

Attachments

  • b4r_log.jpg
    b4r_log.jpg
    8.3 KB · Views: 239
  • bin_file.jpg
    bin_file.jpg
    45.1 KB · Views: 233

Mostez

Well-Known Member
Licensed User
Longtime User
it returned 0x09 which is element 100, oh I got confused, 100 shown in file editor, means 101 elements in array, it should be:
B4X:
Sd.Stream.ReadBytes(cb,0,101) 'read 101 bytes, not 100

Thanks so much Erel
 
Upvote 0
Top