Sub CalculateCRC(MyData As String) As String
Dim a As String
Dim Var2 As String
Dim Var4 As String
Dim Var5 As String
'a = Len(MyData)
a=MyData.Length
'a = Hex(a + 2)
a=Bit.ToHexString(a+2)
a=a.ToUpperCase
'If Len(a) < 2 Then
If a.Length<2 Then
Var2 = "0" & a & MyData
Else
Var2 = a & MyData
End If
'a = Len(Var2)
a=Var2.Length
'Dim b As Integer
'Dim num As Integer
Dim b As Int
Dim num As Int
For b = 1 To a
'num=num+asc(Mid(Var2, b, 1)))
num = num + Asc(Var2.CharAt(b-1))
'Next b
Next
Var4 = num Mod 256
'Var5 = Hex(CByte(((Not Val(Var4)) + 1) AND 255))
Dim tempByte As Byte
tempByte=Bit.And ((Bit.Not(Var4)+1),255)
Var5 = Bit.ToHexString (tempByte)
Var5=Var5.SubString (Var5.Length -2)
'While Len(Var5) < 2
Do While Var5.Length < 2
Var5 = "0" & Var5
'Wend
Loop
'CalculateCRC = Var2 & Var5
Dim tempCRC As String
tempCRC=Var2 & Var5.Touppercase
Return tempCRC
End Sub