Below is the Visual Basic code to calculate the checksum value for the NMEA sentence, which is required for some GPS receivers.
Private Function GetChecksum(ByRef sInString
As String) As String
Dim lCurrent&, lLast&
On Error Resume Next
'-- We don't use the $ in the checksum
If Mid$(sInString, 1, 1) = "$" Then
sInString = Mid$(sInString, 2)
End If
'-- Get the ASC of the first Char
lLast& = Asc(Mid$(sInString, 1, 1))
'-- Use a loop to Xor through the string
For lCurrent& = 2 To Len(sInString)
lLast& = lLast& Xor Asc(Mid$(sInString, lCurrent&, 1))
Next
'-- Pass the data back as a string
GetChecksum = CStr(Hex(lLast&))
End Function