Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
 It is currently Sat Sep 21, 2019 2:41 pm

 All times are UTC - 5 hours

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Checksum calculation for NMEA sentence output from GPSPosted: Sun Feb 27, 2011 9:26 am

Joined: Tue Jul 27, 2010 4:27 am
Posts: 12
Converted from VB for use with Real Studio.

If anyone has a better idea of how to return the two character string, I'd like to hear it!

`Function Checksum(mySum As String) As String  Dim Char(-1) As String, Checksum As Integer, n As Integer, Result As String    ReDim Char(Len(mySum))    For n = 0 to Len(mySum) -1    Char(n) = Mid(mySum,n + 1,1)  next n    for n = 0 to UBound(Char)    if Char(n) = "\$" then continue    if Char(n) = "*" then exit    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    'add preceding zero  if Len(Str(Hex(Checksum))) < 2 then    Result = "0" + Str(Hex(Checksum))  else    Result = Str(Hex(Checksum))  end if    Return Result  End Function`

Steve

Top

 Post subject: Re: Checksum calculation for NMEA sentence output from GPSPosted: Sun Feb 27, 2011 9:59 am
 Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
`Function Checksum(mySum As String) As String  Dim Char(-1) As String  dim Checksum As Integer  dim n As Integer  dim Result As String    char = split(mySum,"")    for n = 0 to UBound(Char)    if Char(n) = "\$" then continue    if Char(n) = "*" then exit    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    Result = Str(Hex(Checksum))  'add preceding zero  if Len(Result) < 2 then    Result = "0" + Result  end if    Return ResultEnd Function`

_________________
Norman Palardy (Real Software)

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 2 posts ]

 All times are UTC - 5 hours

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ General    General    Getting Started    Networking    Databases    Visual Basic to REAL Studio Conversion    Games    Plugins    Tips    Web Control SDK Platform Specific    Windows    Macintosh    Linux    Web Other Topics    Announcements    Off-Topic    Third Party Add-ons