B4R Question How to get the Index of an Array

pokhraj_d

Member
Hello All,
I am trying to parse NMEA sentence in GPS.
The below is the GPS NMEA:
B4X:
$GPGGA,194530.000,3051.8007,N,10035.9989,W,1,4,2.18,746.4,M,-22.2,M,,*6B

Below is my Code:
B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Private bc As ByteConverter
    Private nmea() As Byte="$GPGGA,194530.000,3051.8007,N,10035.9989,W,1,4,2.18,746.4,M,-22.2,M,,*6B"
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    For Each s() As Byte In bc.Split(nmea,",")
        Log("The value of NMEA :",s)
    Next
End Sub

And this is the result I got which is fine:
===============
The value of NMEA :$GPGGA
The value of NMEA :194530.000
The value of NMEA :3051.8007
The value of NMEA :N
The value of NMEA :10035.9989
The value of NMEA :W
The value of NMEA :1
The value of NMEA :4
The value of NMEA :2.18
The value of NMEA :746.4
The value of NMEA :M
The value of NMEA :-22.2
The value of NMEA :M
The value of NMEA :
The value of NMEA :*6B
================
But I want the index of each element of the array like below :
===============
The value of NMEA :$GPGGA -> Index 0
The value of NMEA :194530.000 -> Index 1
The value of NMEA :3051.8007 -> Index 2
==============
How can I achieve this? Please advice.

Thanks-
Pokhraj Das
 

BillMeyer

Well-Known Member
Licensed User
Longtime User
B4X:
Dim Index As Int = 0
 For Each s() As Byte In bc.Split(nmea,",")
        Log("The value of NMEA :",s, " index: ", Index)
        Index = Index = 1
    Next
Hmmm - I think that Index = Index = 1 might just need to be Index = Index + 1 - although I could be wrong :p
 
Upvote 0
Top