----- Original Message ----- From: To: Sent: Wednesday, January 14, 2004 4:16 AM Subject: [OT:] C to VB conversion Hi group! I need to rewrite a relatively simple CRC16 routine from C to VB6. This should not be a problem if I wasn't a C virgin. I just can't get the hang of C syntax. Could someone please have a look at it and point out what I am doing wrong. ***WARNING*** Untested code ahead ***WARNING*** This code compiles in VB6, but has not been tested: Dim CRC16Table(0 To 255) As Integer Public Sub InitCRC16() Dim I As Integer, J As Integer, Crc As Integer For I = 0 To 255 Step 1 Crc = I * 256 For J = 0 To 7 Step 1 Crc = (Crc * 2) Xor ((IIf(Crc And &H8000, &H1021, 0))) Next J CRC16Table(I) = Crc And &HFFFF Next I End Sub Public Function CalcCRC16(ByVal S As String) As Integer Dim P As Integer, Crc As Integer Crc = &HFFFF For P = 1 To Len(S) Crc = CRC16Table(((Crc \ 256) And &HFF)) Xor (Crc * 256) Xor Asc(Mid(S, P, 1)) Next P CalcCRC16 = Crc And &HFFFF End Function Bob Ammerman RAm Systems -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.