String Troubles

dstylesunf

Member
Joined
Jan 4, 2010
Messages
6
Programming Experience
10+
Here is my situation.

I'm through a serial connection getting updates from a gps module and autopilot controller. the string comes as the following:

+++ASP:273,THH:0,RLL:0,PCH:0,***
+++ASP:37,THH:0,RLL:60,PCH:2,***
+++ASP:27,THH:0,RLL:60,PCH:0,***
+++ASP:19,THH:0,RLL:60,PCH:0,***
!!!LAT:32259464,LON:-110823520,SPD:0.00,CRT:0.00,ALT:0,ALH:65535,CRS:0. 00,BER:0,WPN:0,DST:0,BTV:4.39,RSP:0,***


I need to grab the lat and lon figures. Up to this point I've not been able to successfully grab the right characters. Here is my code:

VB.NET:
Private Sub Timer1_Tick(ByVal sender As 

System.Object, ByVal e As System.EventArgs) 

Handles timer1.Tick
        Dim cut As String
        Dim cut1 As String
        Dim cut2 As String
        Dim cut3 As String
        Dim cut4 As String
        Dim cut5 As String
        Dim i As Integer = 0
        Dim a As String = 
SerialPort1.ReadExisting
        TextBlock1.Text = a
        Dim main() As String = a.Split("!")
        If main.Length > 1 Then
            Try
                cut = main(0).Remove(0, 7)
                cut1 = cut.Remove(8, 100)
                cut2 = cut1.Insert(2, ".")
                Label1.Content = cut2
                cut3 = main(0).Remove(0, 20)
                cut4 = cut3.Remove(9, 86)
                cut5 = cut4.Insert(3, ".")
                Label2.Content = cut5
            Catch ex As Exception
            End Try
        End If
    End Sub

I have the lat and long going to two lables. Any help would be greatly appreciated!!
 
Are the LAT and LON fields fixed length? Meaning are they always going to be 8 characters each?

If so I would do this:

VB.NET:
dim intStartPOS as integer = <integer position in string where the '!!!LAT:' token starts>
dim strLAT as string = <SubString of text, starting at intStartPOS + 7, with a length of 8>
intStartPOS = <integer position in string where the ',LON:' token starts>
dim strLON as string = <SubString of text, starting at intStartPOS + 5, with a length of 8>
 
Back
Top