I’m writing a method to calculate a checksum byte for a block of text, which will be sent to an external piece of hardware (the manual for the hardware says, “The value of the checksum is calculated by exclusive-or the entire message.”). I’ve got the following so far:
Dim Char(-1) As String
Dim Checksum As Integer
Dim N As Integer
Char = Split("Test Text","")
For N = 0 To UBound(Char)
If Char(N) = "$" Then Continue
If Checksum = 0 Then
' Yes. Set the checksum to the value.
Checksum = Asc(Char(N))
Else
' No. XOR the checksum with this character's value.
Checksum = Checksum Xor Asc(Char(N))
End If
Next N
Return ChrB(Checksum)
This appears to do what I want, but I don’t think it’s calculating the checksum correctly in all cases, so I’d really appreciate it if any of you kind folks could give me any pointers or suggestions for improvements?