Whats wrong here please ?

FFMan

Member
Licensed User
Longtime User
I'm converting this function from VB, but for reasons i don't understand i get a compile error on the return= line saying missing parameter.

Also, is my loop parsing the whole string, i'm a bit confused wtih strings starting at byte 0 and some functions returning length-1 ?

thanks

B4X:
'An NMEA checksum is calculated as the XOR of bytes between (but not including) the dollar sign and asterisk.
Sub NMEA_Checksum(sentence As String) As String 
  Dim s As String 
  Dim i As Int
  Dim sum(0) As Byte 

  s = sentence.Trim
  sum(0)=0 
  For i = 0 To s.Length+1
    sum(0) =  Bit.Xor(sum(0),Asc(s.SubString2(i,i)))
  Next 
  
  'debug.print "Chk=";CstrHex(sum)
  Return = Conv.HexFromBytes(sum())
End Sub
 

thedesolatesoul

Expert
Licensed User
Longtime User
I'm converting this function from VB, but for reasons i don't understand i get a compile error on the return= line saying missing parameter.

Also, is my loop parsing the whole string, i'm a bit confused wtih strings starting at byte 0 and some functions returning length-1 ?

thanks

B4X:
'An NMEA checksum is calculated as the XOR of bytes between (but not including) the dollar sign and asterisk.
Sub NMEA_Checksum(sentence As String) As String 
  Dim s As String 
  Dim i As Int
  Dim sum(0) As Byte 

  s = sentence.Trim
  sum(0)=0 
  For i = 0 To s.Length+1
    sum(0) =  Bit.Xor(sum(0),Asc(s.SubString2(i,i)))
  Next 
  
  'debug.print "Chk=";CstrHex(sum)
  Return = Conv.HexFromBytes(sum())
End Sub

Remove the '=' after return.
Also s.Length-1 should be used.
 
Upvote 0

FFMan

Member
Licensed User
Longtime User
thanks but i still get

Compiling code. Error
Error compiling program.
Error description: Missing parameter.
Occurred on line: 255
Return Conv.HexFromBytes(sum())
Word: (

Point taken about the title.
 
Upvote 0
Top