Android Question Modbus_CRC16 VB6 To B4A Code problem help


New Member
VB6 verification is written in this way. How to write the code in b4a, can you help me

Function CRC16(data() As Byte) As String
      Dim CRC16Lo As Byte, CRC16Hi As Byte     
      Dim CL As Byte, CH As Byte                
      Dim SaveHi As Byte, SaveLo As Byte
      Dim i As Integer
      Dim Flag As Integer
      CRC16Lo = &HFF
      CRC16Hi = &HFF
      CL = &H1
      CH = &HA0
      For i = 0 To UBound(data)
        CRC16Lo = CRC16Lo Xor data(i)
        For Flag = 0 To 7
          SaveHi = CRC16Hi
          SaveLo = CRC16Lo
          CRC16Hi = CRC16Hi \ 2          
          CRC16Lo = CRC16Lo \ 2         
          If ((SaveHi And &H1) = &H1) Then 
            CRC16Lo = CRC16Lo Or &H80      
          End If                          
          If ((SaveLo And &H1) = &H1) Then 
            CRC16Hi = CRC16Hi Xor CH
            CRC16Lo = CRC16Lo Xor CL
          End If
        Next Flag
      Next i
      Dim ReturnData(1) As Byte
      ReturnData(1) = CRC16Hi              'CRC高位
      ReturnData(0) = CRC16Lo              'CRC低位
      CRC16 = Hex(ReturnData(0)) & Hex(ReturnData(1))
  End Function